Trigger Action Framework (TAF)
The Trigger Action Framework (TAF) provides a global Apex class and custom metadata types for you to configure trigger logic with, including turning trigger functions on and off as well as configuring the order in which each trigger runs. The framework can be used with both Apex classes and flows and works for both Scientific Publications Cloud code and custom code, such as standard objects, custom objects, and objects from installed packages.
Enable a trigger
To enable a trigger on an sObject:
Call the Dynamic Trigger Handler (
TAF_DynamicTriggerHdlr) global Apex class within the trigger body of the sObject and pass a running key to the run(key) method. The running key is designed to prevent duplicate calls, and Mavens recommends setting the running key to be name of the trigger handler.Create a Trigger sObject Setting (
mvn__TAF_sObject_Trigger_Setting__mdt) metadata record for the sObject.If the sObject is from an installed package, separate the namespace from the API name of the object and set the Object Namespace (
mvn__TAF_Object_Namespace__c) and Object API Name (mvn__TAF_Object_API_Name__c) fields accordingly.
Complete the steps in the sections below depending on if the trigger should call an Apex action or a flow action.
Trigger an Apex action
If the trigger should call an Apex class:
Write an Apex class that defines the trigger action and extends one or more of the interfaces defined in mvn.TAF_TriggerAction.
Create a Trigger Action (
mvn__TAF_Trigger_Action__mdt) metadata record for the action that should be executed on the sObject and the context in which it executes.Set the Apex Class Name (
mvn__TAF_Apex_Class_Name__c) field to the name of the Apex class.Set the Apex Class Namespace (
mvn__TAF_Apex_Class_Namespace__c) field to the namespace of the Apex class.Set the Order (
mvn__TAF_Order__c) field as appropriate.Set one or more of the contexts for it to run. You set the context by selecting what, if any, SObject type should be passed to your trigger for a given trigger context.
All contexts set must be to the same SObject type. If you need your trigger fired for multiple objects, make multiple Trigger Action Records, one for each object.
The class must have implemented the corresponding interface for the context.
Trigger a flow action
If the trigger should invoke a flow:
Create an autolaunched flow that defines the trigger action with the following flow resource variables:
Table 162. Autolaunched flow resource variablesVariable name
Variable type
Available for input
Available for output
Available contexts
Description
record
record
yes
yes
insert
update
undelete
The new version of the record in the DML operation.
recordPrior
record
yes
no
update
delete
The old version of the record in the DML operation.
Create a Trigger Action (
mvn__TAF_Trigger_Action__mdt) metadata record for the action that should be executed on the sObject and the context in which it executes.Set the Apex Class Name (
mvn__TAF_Apex_Class_Name__c) field toTAF_TriggerActionFlow.Set the Flow Name (
mvn__TAF_Flow_Name__c) field to the API name of the flow.Set the Order (
mvn__TAF_Order__c) field as appropriate.(Optional) Check the Allow Flow Recursion? (
mvn__TAF_Allow_Flow_Recursion__c) checkbox (i.e., set totrue) to run the flow recursively.
Bypass a trigger or action
Triggers can be bypassed on entire sObjects, by specific actions, and by users and profiles and can be controlled through both custom metadata records and code.
Bypass with custom metadata records
To bypass all triggers on a single sObject, check the Bypass Execution (mvn__TAF_Bypass_Execution__c) checkbox (i.e., set to true) on the respective Trigger sObject Setting (mvn__TAF_sObject_Trigger_Setting__mdt) metadata record. To bypass all instances of a trigger action, check the Bypass Execution (mvn__TAF_Bypass_Execution__c) checkbox (i.e., set to true) on the respective Trigger Action (mvn__TAF_Trigger_Action__mdt) metadata record. The bypasses will remain active until the Bypass Execution field for each metadata record is unchecked.
Warning
You may bypass any default Trigger Action metadata records to disable product trigger actions. However, doing so can, and will, affect product functionality.
To bypass or execute triggers and actions by users or profiles, use the Bypass Permission (mvn__TAF_Bypass_Permission__c) and Required Permission (mvn__TAF_Required_Permission__c) fields on the Trigger sObject Setting and Trigger Action custom metadata types. The former uses a custom permission to determine if a trigger or action should be bypassed for the running user while the latter uses a custom permission to determine if a trigger or action should execute for the running user.
Bypass with code
To bypass and execute triggers with code, call the appropriate Dynamic Trigger Handler (TAF_DynamicTriggerHdlr) global methods in your custom Apex classes and flows. Any bypasses will remain active until the bypass flags are cleared.