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
Zach AckermanZach Ackerman 

Update Opportunity Field Based on Contact Role.

I want to update a custom field Original_Campaign__c on the opportunity. I want to populate that field with the contact roles Original_Campaign__c. Below is what I have, but it is not populateing the information. 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
trigger OpportunityOriginalCampaignUpdate on Opportunity (after insert, after update) {

 

    List<Contact> conList = new List<Contact>();

   

                    OpportunityContactRole ContactRoles = [select OpportunityID, ContactID from OpportunityContactRole where OpportunityID =: trigger.old];

                     

                  

                Contact con =[Select Original_Campaign__c from Contact where id=: ContactRoles.ContactId];
               


                        Opportunity opp = [Select Original_Campaign__c from Opportunity where id =: ContactRoles.OpportunityID];
                                                                             
                 opp.Original_Campaign__c = con.Original_Campaign__c;
                                                                                                       

                  
}
Bhaswanthnaga vivek vutukuriBhaswanthnaga vivek vutukuri

there might be multiple contacts associated with same opportunity, make sure are retrieving the correct one and I think code you posted here is pseudo code.