0

I am trying to select data from a couple objects at the same time using Javascript.

I want to select the LOB__C, risk_state__c FROM Opportunity and the Contact's firstname and lastname that is related to that Opportunity. I can't figure out how to do that.

Thanks guys.

2
  • How is the contact related to the opportunity? Contact Roles, custom relationship? Commented Apr 2, 2012 at 18:29
  • Hi Jeremy, I thought I had it related, but it wasn't. What would be be best practice? Should I query through the Account object or add a reference to Opportunity. Contact(parent) -> Opportunity(child). Still not sure how to create the query. Thanks for the help thus far. Commented Apr 2, 2012 at 18:38

1 Answer 1

3

If you need to access a single Contact, you would need to add a reference field on the Opportunity to the Contact (using either a Lookup or Master-Detail relationship field).

From there, you can query like this:

Select LOB__c, risk_state__c, 
    Contact__c, Contact__r.FirstName, Contact__r.LastName From Opportunity 

If you're looking at accessing all/multiple contacts for an Opportunity, store them in the OpportunityContactRole object and use a query like this:

Select LOB__c, risk_state__c,
    (Select ContactId, 
        FirstName, LastName From OpportunityContactRoles) From Opportunity
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.