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
Paula Kern 4Paula Kern 4 

soql from Opportunity to Account to Contact. Get Primary Contact name

Hi all,

I have a soql query where opportunity is the primary object.  i need to add to it the Name of the primary contact from the Contact Object.  I'm having trouble traversing the Opportunity to Account to Contact relationship.  Can someone help please
Alain CabonAlain Cabon
Hi,

SELECT Id, Name,
(SELECT Contact.Name FROM AccountContactRoles  WHERE IsPrimary = TRUE),(select id,name from opportunities) 
FROM Account WHERE Id in (select accountid from opportunity where id = '0060Y000002sQ4VQAU')

The idea is to use Account instead of Opportunity.
There are surely other alternatives.