1

I'm trying to frame a single SOQL on opportunity with fields from Multiple objects like Account Name, Contact Name ,Contact Ph , Contact Email and the Opplineitems. I'm not sure how to get the Account Name and Contact Details from opp which has lookup.

 Opportunity Op=[select id,Name,Stagename,Account__r.Name,(select Product_Name__c,Bid_Type__c from OpportunityLineItems) from opportunity where stagename='Closed-Won' and id=:opptyid];
  • 1
    helpful tip -- OOB SFDC relationships never use __r; OOB SFDC fields never use __c. Hence relationship from Opportunity to Account is simply account.someAccountOOBfieldname or account.someAccountCustomfieldname__c – cropredy Aug 21 '15 at 19:40
0

Unless you have a contact related to the Opp via a lookup then you will have to do two queries. (or a subquery on via Contact Roles child object on Opp if that fits your need) For Account use

Account.name

From the query on Opp

Since you have a lookup to contact, use the API name replacing the __c with __r and add .name or whatever other field you need

  • We have lookup to Contact from opportunity, I need to get the details of this contact. – Salesforce Learner Aug 21 '15 at 15:34
  • The use the Contact__r.Name (Or whatever the API name is of the Lookup to the contact – Eric Aug 21 '15 at 15:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.