I initially wrote the below trigger to update opportunity field based on value in account field. However, it should be other way around.
Explaining: When an opportunity is created/Edited and if the lookup field at account level called Sales_Manager__c in not null, the same value should be populated onto Opportunity lookup field Sales_Manager__c
trigger updateOppSalesManager on Account (After update)
{
/* checking the value of sales manager at account level by looping through Opportunities */
List<Opportunity> opps = [
Select Id, sales_manager__c, account.sales_manager__c
From Opportunity
Where AccountId In :Trigger.newMap.keySet()
];
/* Updating opportunity field with the value from account Sales_manager__c*/
for (Opportunity opp : opps) {
opp.sales_manager__c = opp.Account.sales_manager__c;
}
update opps;
}
I tried in every possible way i can by using set: to set account id , list: to loop through opportunity with the account ID , also used maps, but with no luck. Any Help, Suggestion, Guidence will be very useful for me.
Thank you Sam
Process Builder
instead.