You need to sign in to do that
Don't have an account?
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))];
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