+ Start a Discussion
Sainath VenkatSainath Venkat 

trigger to update field on opportunity from mutual plan from account

Hi everyone,

Can anyone help me in writing a trigger for below scenario, I have 3 objects
1) Opportunity
2) Account
3) Mutual_Plan__c

opportunity is having lookup to account,Mutualplans objects and Mutual_Plan__c has lookup to Account objects
On opportunity, on selecting account and clicks on save button, I need to populate the MutualPlan__c field on opportunity with mutual plan record id.
On opportunity I have Datefield__c, if I select this date field and account field then I need to fetch the Mutualplan record that is related to the account and populate it on Mutualplan__c field on opportunity.

Can anyone help me out in this issue here.
Hi Sainath,

1) You need to write a before insert & before update trigger on opportunity which condionally checks if the opportunity record satisfies to have date field and account lookup.
2) In order to make the above logic work, you need to query the Mutual plan records tied to selected account on opportunity and keep it in a Map<Id,MutualPlan__c> where in Id-> AccountId. 
3) Iterate the opportuntiy records again and populate the mutual plan field on opportuntiy from the collected record. 

Hope this gives to highlevel background to start your actual development. 

Choose this reply as best answer if you feel its helpful.