Table-Driven Trigger Management is one of the vital and powerful features in Salesforce Non-Profit Success Pack (NPSP) and Education Data Architecture (EDA). It highly resonates with the trigger-based applications of education cloud or non-profit cloud. Table-Driven Trigger Management is a design or framework that sits on top of apex triggers to control the order of trigger’s handler class executions and allows us to skip certain code blocks based on our choice. It ensures the trigger best practices automatically with very minimal effort from developer or administrative end. Beyond handler class order control, it also provides some additional benefits like asynchronous execution and specific user(s) level execution control. Table-Driven Trigger Management is abbreviated as TDTM. It is expected to have either one of these packages (NPSP or EDA alias Higher Ed) and utilize benefits of TDTM in your organization.
Creating a Trigger Handler in TDTM step by step:
If you are an existing customer of NPSP or EDA package, you already have it. You need to have either one of these packages in your org to play with TDTM.
Installing these package(s) readily comes with TDTM trigger for each object in your org except custom objects which is not part of your NPSP or EDA Package, though you can create your own TDTM trigger for your custom objects. By that way, we can enforce our custom object trigger to follow the TDTM way of execution instead of conventional apex trigger way.
Trigger Handler Records
Navigate to Trigger handler records list view by clicking on
App Launcher -> view all -> and Search for “Trigger Handlers.”
Trigger handler record stores information related to which class to run in response to DML performed on an object. A trigger handler records will be like below in a list view. It is named TDTM because the entire trigger execution is arranged in a table format.
A Trigger Handler Record Sample
Below a single trigger handler record is given along with description and usage of each field.
Trigger Handler Name:
A unique name to represent a handler record. Not a mandatory field.
Name of the trigger handler class that has business logics.
Name of the object (API Name) this handler runs on top of. It should be the API Name. If it has namespace, namespace should be appended with trailing underscore.
Order in which this code module (handler class) should run. This is very crucial in terms of order of execution. If the load order higher, it is considered as the recently executed code module.
We can escape the handler class from execution by setting up filters. We could decide to run the class only if field mentioned in the field filter has specific value. Filter Field holds API name of the field we decided to consider as filter. E.g., This can have Account’s Rating field API name “Rating.”
The filter value for the field that we defined “Filter Field” above.
Usernames to Exclude:
This field contains the usernames, for them we can exclude the execution of the entire trigger handler class. We can specify multiple users by separating them in a semicolon.
Trigger event(s) that we need to consider in our trigger handler class. This same as the trigger events available for usual apex trigger.
We can run this module asynchronously in the transaction by checking this checkbox.
If this is unchecked trigger handler is omitted from execution. It should be active to execute the handler module class.
Owned by namespace:
Namespace belongs to the handler class. If there is no namespace, we can leave it as blank.
How to create a handler class in TDTM?
- Create a new class, make sure it is having “global” access specifier.
- Your class should extend “TDTM_Runnable” . Based on package it has namespace prefix.
- Once you extend “TDTM_Runnable,” you need to override “run” method in your handler class.
- Overridden “run” method should be returning the instance of “TDTM_Runnable.dmlWrapper.”
Refer the below code snippet that has handler class named “NEP_CourseConnectionHandler_TDTM.”
In the below snippet, TDTM_Runnable has a prefix with hed that represents namespace of the Higher-Education cloud managed package (EDA).