You need to sign in to do that
Don't have an account?
Parsa Motamedi
Create a map of object and related object
Hi,
From a before insert trigger on opportunity, I want to get all the opportunities inserted, find their related contact record and populate a field on the contact record with its associated opportunity record.
It seems like a simple concept, and I know I have to use a Map to achieve this, but to minimize the number of SOQL queries, it becomes real tricky.
Any help would be appreciated!
Parsa
From a before insert trigger on opportunity, I want to get all the opportunities inserted, find their related contact record and populate a field on the contact record with its associated opportunity record.
It seems like a simple concept, and I know I have to use a Map to achieve this, but to minimize the number of SOQL queries, it becomes real tricky.
Any help would be appreciated!
Parsa
First collect the IDs of all the contacts that are going to be updated, then put them into a map of IDs and Contacts, set the Latest Opportunity, and finally update them.
All Answers
What I'm trying to fill is a field called Latest_Opportunity__c on the Contact record.
First collect the IDs of all the contacts that are going to be updated, then put them into a map of IDs and Contacts, set the Latest Opportunity, and finally update them.
I have gone through your question. Please try below code -
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com