+ Start a Discussion
ChickenOrBeefChickenOrBeef 

Manual account transfer doesn't trigger workflows/triggers?

Hey everyone,

I have an After Update trigger on the Account object that transfers the Contact owners to the current Account owner, while also setting a Contact field to a certain value. The problem is that when I manually transfer the account in Salesforce, the trigger doesn't work. But if I transfer the account by using something like Dataloader or Workbench, the trigger works.

Does manually transferring an Account in Salesforce not cause triggers to run?

Thanks!
-Greg
Best Answer chosen by ChickenOrBeef
Peter_sfdcPeter_sfdc
That  certainly doesn't sound right. 

Have you tried writing in some debug statements to see if the trigger is actually being fired, or if there is some condition that is just blocking the successful execution of the logic? 

Can you share you code to help understand better what your trigger is doing? 

All Answers

Peter_sfdcPeter_sfdc
To clarify: 

 
"...transfers the Contact owners to the current Account owner..."
 
I am unclear what you mean to say by this. Do you mean that the trigger changes ownership of the Account to match the current owner of the Contact? 

To answer the more broad question: typically an action taken in the UI will invoke triggers in the same way that an action taken by the API (data loader/workbench/etc) will. But there are some exceptions, for instance cascade deletes do not fire delete triggers on child objects. Mass reassignment, also does not fire triggers. In the Apex documentation there is a big list of actions, in fact, that do not fire triggers. I would suggest you take a look at that in the section titled, "Operations that Don't Fire Triggers" (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_ignoring_operations.htm" target="_blank). Perhaps you will find there that the way you are assigning the account ownership falls under that list? 
ChickenOrBeefChickenOrBeef
Hey Peter,

The trigger changes ownership of the Contacts so that the Contacts are owned by the same owner of the Account. The trigger also updates a custom field on all those Contacts.

Thing is, when you manually transfer an account in Salesforce, all the contacts are transferred to that new owner by default. But I had to write the trigger for when Accounts are transferred via the Dataloader. So I never knew that the trigger wasn't actually running upon manual transfer, since Salesforce did it by default.

But I'm now adding to that trigger so it updates that custom field I mentioned, but I'm noticing that the custom field doesn't update upon manual transfer. 

So just to clarify, this is what happens in both scenarios:

-Manual Account Transfer: Contacts are transferred as well (default Salesforce feature), but the custom field on the Contacts doesn't update
-Dataloader Account Transfer: Contacts are transfer as well (my trigger), and the custom field is updated (my trigger)

I don't think my situation is found anywhere in that document you linked, so that makes this even more confusing.

Thanks!
-Greg
Peter_sfdcPeter_sfdc
That  certainly doesn't sound right. 

Have you tried writing in some debug statements to see if the trigger is actually being fired, or if there is some condition that is just blocking the successful execution of the logic? 

Can you share you code to help understand better what your trigger is doing? 
This was selected as the best answer
ChickenOrBeefChickenOrBeef
Hey Peter,

After including some debug statements (I don't know why I didn't try that before) I figured out the issue. In the IF statement when looping through the contacts, I had it only update the contacts if the Account owner was different than the Contact owner. But since Salesforce transfers the contact owner by default, the contacts already have the same owner whenever you manually transfer the account in Salesforce.

So I just had to remove the part in my IF statement that said "c.OwnerId != act.OwnerId".

Thanks for your help!
-Greg
Peter_sfdcPeter_sfdc
Glad you've worked it out.