Table Driven Trigger Management Framework

Author

Trigger frameworks – not something we’d look to change too often but traditional trigger frameworks don’t play well with modern development practices in Salesforce.

Why? Under older frameworks, trigger and handler classes typically initialize classes or call methods explicitly, meaning these central components are technically dependent on the logic they call.

Table-Driven Trigger Management (TDTM) is a tool you can use to manage the apex triggers. Salesforce introduced this concept out of the box for Nonprofit Starter Pack (NPSP) and Education Data Architecture (EDA). TDTM is new to most Salesforce users, which is why you haven’t heard much about it.

As EDA and NPSP rely heavily on triggers. When you have multiple triggers in the same Salesforce object, the order of trigger execution is non-deterministic.

TDTM helps you manage these apex triggers (behind-the-scenes automation). The benefits of TDTM are many. Eventually, it may introduce a risk of possible data issues due to a lack of control over triggers and their execution order. When disabling existing trigger functionalities, traditional triggers need developers to comment APEX code. Therefore, it could be difficult to maintain traditional Salesforce triggers in an Org. Developers might have a challenge in understanding and debugging problems. These concerns have been resolved with Salesforce TDTM.

That’s where TDTM comes in! TDTM grants you to easily rearrange the order of things via a table in the Salesforce interface. With TDTM you can tell your Apex trigger: do A first, then B, then C. All without code!

The Trigger Handler is then charged with the task of calling these classes when appropriate, which gives the added advantage of allowing us to centralize error handling for triggers around the Trigger Handler.

That leaves us with the following fields in our custom object Trigger_Handler__c:

  • Class__c: the handler class to run
  • Object__c: the object that, when being modified, will perform the class run
  • Trigger_Action__c: the actions on which the class will execute (before insert, after the update, and so on)
  • Load_Order__c: the order of execution in which classes for the same object, and with the same actions, will run
  • Asynchronous__c: a flag that defines whether the class will run synchronously or asynchronously

TDTM only works when you already integrated this pattern into your Apex code.

Pranshu Goyal, Director of Products at Mirekta, states: “We envision DSM to be used by every small to a medium-sized organization dealing with bad data and want to get rid of duplicates easily with no cost. We have faced issues dealing with duplicates in our organization. That inspired us to make a solution that is not only simple to use but can be used widely to make the organization’s data clean to make them more efficient and productive. We want DSM to be a solution for every organization looking for duplicate management capability better than the Salesforce out-of-the-box solution with no additional cost.”