You need to sign in to do that
Don't have an account?
Ty Whitfield
How to retrieve contact role information from an opportunity
Diving back into Apex so I'm a bit rusty. What we are looking to do is to create a trigger after insert and after update that will identify the Primary contact on the opportunity. For that Primary contact, pull a custom field from the contact and then update a custom field on the opportunity with that value.
I know how to update the opportunity field but what I don't understand is how to pull the contact role information. Can someone point me in the right direction?
I know how to update the opportunity field but what I don't understand is how to pull the contact role information. Can someone point me in the right direction?
All Answers
you need to change "YourCustomField" and "YourOpportunity" to the proper values and you should get the id and the field for the contact. Let me know if it was helpful for you.
What I'm thinking is that when I try to insert the opportunity in the test, I insert the opportunity then the opportunitycontactrole so when my trigger starts after insert, a contact hasn't been tied to the opportunitycontactrole.
Here is my Trigger:
Here is my test
If you can just explain to me the map statements. I don't quite understand what is being done.
the last part is to get the primary contact related to the oppotyunity in the loop.
remove the "Map<id,contact>" and the 2. That was a typo.
read this: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_map.htm
mark my answer as the best if it helped you.