Order of execution managed vs. non-managed code

Does managed package trigger code always execute before the org’s user defined trigger code?

(i.e. Is the before insert logic of all managed packages that are installed in an org executed before the locally defined before insert logic?)

I have not been able to locate documentation specifically noting order of execution packaged vs. non-packaged code. In looking at the debug logs, it appears that triggers and workflows from the managed packages are always executed first but I would like to see documented evidence of this before accepting it as fact.


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.

Source : Link , Question Author : Mark Pond , Answer Author : Jonathan Hersh

Leave a Comment