Think. Build. Salesforce Solutions.

Salesforce Consulting Services across Salesforce Clouds & Across App Lifecycles

Blog

Table Driven Trigger Management Framework

By |2021-06-29T05:32:49+00:00June 29th, 2021|

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.

TDTM Framework

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.

table driven trigger management

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.

Let’s dig into the factors that make TDTM necessary in your Salesforce Org.

  • More control over your code – With traditional triggers, there is no guarantee that they will run in a distinct order. With trigger management, you can choose when to run which trigger code.
  • Admin Friendly – Salesforce Admin can enable/disable the trigger without developers. Comment/un-comment trigger codes and decreasing deployments cycles are not required.
  • Developer Friendly – It is easy to understand, debug problems and develop new plug-in features.
  • Scalability – It can help scale triggers into features to simplify functions.
  • Disable Specific Pieces of Code – You need to disable the code when you Import large sets of data, integrate with external systems, and Troubleshoot code errors.

Leave A Comment