Action Configuration
At the heart of the framework is the Trigger Action (seven20__Trigger_Action__mdt) metadata type, this metadata type acts as the primary control centre for both packaged and custom trigger actions. Each record represents a single trigger action and its associated invocation configuration. Below is an overview of a trigger action record:
| Field Label | API Name | Type | Description |
|---|---|---|---|
| Label | MasterLabel | Text(40) | A user friendly label for the trigger action |
| Name | DeveloperName | Text(40) | The API name of the trigger action |
| Apex Class Name | seven20__Apex_Class_Name__c | Text(40) | The name of the Apex class that implements the trigger action |
| Namespace | seven20__Namespace__c | Text(40) | The namespace prefix of the Apex class that implements the trigger action, if applicable. For no-namespace orgs, this should be blank |
| Trigger Object | seven20__Trigger_Object__c | Metadata Relationship(Entity Definition) | A lookup to the object that the trigger action should be invoked for |
| Trigger Object (Special) | seven20__Trigger_Object_Special__c | Picklist | A picklist of objects which aren't supported by the entity definition which can be triggered from, e.g. User or Task |
| Trigger Context | seven20__Trigger_Context__c | Picklist | The context in which the trigger action should be invoked, these values match the TriggerOperation Enum values |
| Invoke Order | seven20__Invoke_Order__c | Number(3, 2) | The order in which the trigger action should be invoked, relative to other actions with the same object and context. Lower numbers are invoked first |
| Is Active | seven20__Is_Active__c | Checkbox | Whether the trigger action is active or not. If this is unchecked, the trigger action will not be invoked |
While Invoke Order supports decimal invoke orders, these should be avoided unless absolutely necessary.
If an action supports multiple context types, multiple records are required, one for each context.
Disabling actions declaratively
Actions can be disabled as required by unchecking the Is Active checkbox on the trigger action record. This is useful for disabling actions on a temporary basis, such as when performing data migrations, or if critical issues are discovered in a piece of recently deployed code.
Additionally, if the need arises, actions can be globally disabled. This is achieved by enabling the Seven20 Configuration setting which has a developer name of Disable_All_Triggers.
Disabling actions programmatically
Actions can also be disabled via apex on a temporary basis if the need requires. The seven20.TriggerHandler class has several exposed methods to achieve this, they are:
void setGlobalDisabledStatus(Boolean disabled) - Used to set the global trigger action disable flag. Default value is based on the value of the Disable_All_Triggers configuration setting.
Boolean getGlobalDisabledStatus() - Returns the current status of the global trigger action disable flag.
void setTriggerActionDisabledStatus(Id actionId, Boolean disabled) - Used to disable, or re-enable, a specific trigger action for the current transaction. Does not override the global disabled flag, or the record's Is Active flag.
Boolean getTriggerActionDisabledStatus(Id actionId) - Returns whether a specific action has been explicitly disabled through the setTriggerActionDisabledStatus method.
The effects of the above methods only persist for the current transaction.