function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Reppin505Reppin505 

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 :oppWithNewEndDates.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;
}
werewolfwerewolf
Well what is the error you're getting?

Did you run this with Debug Log on (or from a testMethod) so you can see how it's executing and spot any errors?

And what is it you're actually trying to do?  This seems nonsensical to me.