Why Isn’t My Apex Trigger Firing?
Have you ever written a trigger and tested it to the point where it’s working perfectly, only to discover that your trigger isn’t firing? Frustrating, isn’t it? I mean, triggers always fire when the object is inserted, updated, deleted, or undeleted! Don’t they?
It turns out there are several circumstances when even the best-written trigger just doesn’t fire. According to Salesforce, triggers don’t fire for all DML operations: they fire only when a DML operation is processed by the Salesforce Java application server. The following operations are not processed by the Java application server, and therefore, triggers don’t fire when these operations occur:
- Cascading delete operations. When a child record in a master/detail relationship is deleted because the parent record was deleted, the child’s trigger doesn’t fire.
- Updates of child records that occur because of a merge operation. When you merge two Leads into a single Lead, for example, although child records of the “losing” Lead are re-parented to refer to the “winning” Lead, the child triggers don’t fire.
- Mass emails performed via the UI. When you click the “Mass Email” button at the bottom of the Contact or Lead tab, a Task gets created for each Contact or Lead you email, but the Task trigger doesn’t fire.
- Mass campaign status changes performed via the UI
- Mass address updates performed via the UI
- Mass approval request transfers
- Mass division transfers
- Pricebook management performed via the UI
- A custom field definition is changed in a way that impacts the data stored in that field, such as changes to picklist value configurations
In addition, some triggers fire only if you’ve configured them to do so. For example, “before” triggers don’t fire during Lead conversion unless you’ve enabled that in your org.
For a full list of when triggers don’t fire, see http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_ignoring_operations.htm.