You need to sign in to do that
Don't have an account?

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;
}
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;
}
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.