function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Savi3Savi3 

To query Opportunity field

Hi,

 

 Can someone help me to query some fields of Opportunity along with contact fields.

Opportunity has a field Account and there are contacts for this account. I want to retrieve some fields of opportunity and fields of contacts with the accountId .

 

Please help..

V1nitV1nit

Select Id, Name, (Select Id, Name From Opportunities), (Select Id, Name From Contacts) From Account

DharshniDharshni

 

You have to query the accountID field from Opportunity and then use this to query the related account separately.

 

Id accId = [SELECT accountID FROM Opportunity where Id=:oppID].accountID;

List<contacts> contactList = [SELECT id,(SELECT id,name from contacts) from Account where id=:accID];

 

 

prady-cmprady-cm

V1nit,

 

your query would give contact records for all accounts, is there a way we can query opportunities and from those opportunities take the accounts and in turn get contacts.

 

I am not sure if this is even feasible.

 

Anybody has ideas?