You need to sign in to do that
Don't have an account?
Reppin505
Trigger to Update Related Account Record from Opportunity Object - Not Working
Desparately need some help. I cannot get this trigger to update the related acount record fromt the opportunity object.
trigger updateAccountsOnChange on Opportunity (before update) { Map<Id, Opportunity> oppWithNewEndDates = new Map<Id, Opportunity>(); for (Integer i = 0; i < Trigger.new.size(); i++) { if ( (Trigger.old[i].Name != Trigger.new[i].Name)) { oppWithNewEndDates.put(Trigger.old[i].id,Trigger.new[i]); } } List<Account> updatedAccounts = new List<Account>(); for (Account c : [SELECT ID, Name FROM Account WHERE ID in ppWithNewEndDates.keySet()]) { Opportunity parentOpportunity = oppWithNewEndDates.get(c.Id); c.Description = parentOpportunity.Id; //c.Salutation_Name__c = parentOpportunity.Name; //c.Name = parentOpportunity.Name; updatedAccounts.add(c); } update updatedAccounts; }
Here are two versions of the code that works to successfully complete this trigger, just in case anyone needs this type of reference.
Version 1: