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
Anna SignorAnna Signor 

Account trigger not firing when account owner changes

I have am writing a trigger on Account that is supposed to fire when the Account Owner is changed. I tested the logic using classes and everything is doing its job, except the trigger is simply not firing. I then changed it to be triggered by different fields and it works just fine in those cases. I read something about Account Change Owner wizard operations not initiating process flows, is that true for triggers as well? What are my alternatives here?
Not firing:
trigger AccountTrigger on Account (after update) {
    System.debug('Account Team Trigger fired');
    for(Id acctId: Trigger.newMap.keySet()){
       if(Trigger.oldMap.get(acctId).OwnerId!= Trigger.newMap.get(acctId).OwnerId){
       classes.dostuff();     
  }
}
DML;
}
However, this one is firing, only when I edit from the edit page, which is not possible for Account Owner:
trigger AccountTrigger on Account (after update) {
    System.debug('Account Team Trigger fired');
    for(Id acctId: Trigger.newMap.keySet()){
       if(Trigger.oldMap.get(acctId).otherField__c!= Trigger.newMap.get(acctId).otherField__c){
       classes.dostuff();     
  }
}
DML;
}


 
Mubeen QawiMubeen Qawi
Hello there, Its strange that its not working lol, try the below approach. This is exactly how I implemented in our org. for similar use case and works like a charm.
 
for(Account newAcc : newAccs.values()) {
            Account oldAcc = oldAccs.get(newAcc.Id);
            if(newAcc.OwnerId != null && oldAcc.OwnerId != newAcc.OwnerId) {
            }
          DML
        }

MQ

 
Mubeen QawiMubeen Qawi
newAcc = Trigger.newMap
oldAcc = Trigger.oldMap
Anna SignorAnna Signor
I appreciate the reply, but you see, my problem is that the trigger is not even firing, note my debug statement before any logic controls or DMLs.
With that being said, your iteration looks simpler so I will change it. Thank you!