Order of execution managed vs. non-managed code

AFAIK, it's irrelevant whether you have managed or unmanaged triggers (or both). The guidance I've heard is that any time you have multiple triggers on the same object in the same firing context (e.g. multiple before insert triggers on Lead), then the order of execution is undefined. It is best to have just one trigger in each context.

Edit: It is undefined. From the docs:

The order of execution isn’t guaranteed when having multiple triggers for the same object due to the same event. For example, if you have two before insert triggers for Case, and a new Case record is inserted that fires the two triggers, the order in which these triggers fire isn’t guaranteed.


The order of execution isn’t guaranteed when having multiple triggers for the same object due to the same event. For example, if you have two before insert triggers for Case, and a new Case record is inserted that fires the two triggers, the order in which these triggers fire isn’t guaranteed.

Please see below link

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_order_of_execution.htm


Order of Trigger execution (Managed and un-managed), there is no priority set for which package's trigger will be fired for particular DML OP.

The only order follows is before, after trigger. If there are two triggers on before insert on is managed and other one is user created, then we can not guarantee of which will fire first.

But in most cases it happened to see in debug logs that managed package trigger got fired first but it doesn't happens each time. I have seen in several debug logs where 6 to 7 triggers got fired including managed and unmanaged package triggers, they were all random, in which first is user defined, second from managed package and vice-versa. Also It is not happens that all managed trigger will fire in sequence and unmanaged by sequence, they are all random.

I never read a official documentation specifying the execution of triggers by managed package and unmanaged package. If someone, then please share.

When creating package it is best practice to create one trigger for same trigger type. And use classes to control the behaviour by checking some condition in trigger.