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.

MJ Kahn, SVP of Technology at OpFocus

about the author

MJ Kahn

At OpFocus, MJ architects and constructs solutions that would impress the builders of the pyramids. She solves technical puzzles that would frustrate daVinci. She leaps tall buildings (like the new Salesforce tower) in a single bound.

Well ok, maybe she doesn’t. But she does help lead an amazing team of smart, talented, and dedicated consultants who do. MJ’s job at OpFocus is provide technical leadership and guidance to OpFocus clients and team members so that, working together, we can create innovative yet practical solutions to real-world business problems within the Salesforce ecosystem.

Prior to OpFocus, MJ built an extensive background in technology and has held a variety of development, consulting, and management positions at companies like Sybase, Vignette, and Honeywell, among others. In these roles, MJ’s focus was helping companies effectively and intelligently use technology to solve business problems. An Apex and Visualforce consultant since mid-2008, MJ has worked with scores of companies to help them understand and utilize platforms like Force.com to solve business issues and also guide them in developing their own AppExchange product offerings.