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
Shawna.ax1585Shawna.ax1585 

Apex Trigger to update Contacts associated with specific opportunities

I'm trying to update a field located on the contact record of contacts  referenced on the contact roles related list of opportunities.  (So I want to select contacts that are tied to a specific opportunity)

I'm receiving the below error on my trigger. Can someone help?  Is this possible to do?

 

 

Error: Compile Error: Nesting of semi join sub-selects is not supported

 

 

Contact[] contactsNetNewWon = [SELECT Id, Net_New_Won_Survey_Needed__c
FROM Contact
WHERE Active_Contact__c = true
AND Id IN
(SELECT ContactID
FROM OpportunityContactRole
WHERE OpportunityID IN
(SELECT Id FROM Opportunity
WHERE Id IN :oppsNetNewWon))];

Avidev9Avidev9

Well you cannot run this query directly you have to break this into steps

 

Step 1 : Query on OpportunityContactRole

 


List<OpportunityContactRole> OpportunityContactRoles = [SELECT ContactID FROM OpportunityContactRole WHERE OpportunityID IN(SELECT Id FROM OpportunityWHERE Id IN :oppsNetNewWon)];

 

Step 2: Collect all the ContactId in list by iterating over the above list say the list name is "ContactIds"

 

Step 3 :SELECT Id, Net_New_Won_Survey_Needed__c
FROM Contact
WHERE Active_Contact__c = true
AND Id IN :ContactIds