TRG_Base
Class · Group: Triggers
global inherited sharing virtual class TRG_BaseKnown Derived Types: TRG_ExecuteValidationRules
The base class for trigger actions, designed to be extended and implement relevant interfaces. This class provides the core functionality for executing trigger actions based on the trigger context, with support for bypassing specific SObject types. It is adapted from the apex-trigger-actions-framework.
Example
public with sharing class TRG_SetFoobarDefaults extends TRG_Base implements IF_Trigger.BeforeInsert
{
public void beforeInsert(List<SObject> newRecords)
{
for(SObject record : newRecords)
{
if(record.get(Foobar__c.Name) == null)
{
record.put(Foobar__c.Name, 'Default');
}
}
}
}See Also: TRG_Dispatcher, IF_Trigger
Methods
| Method | Description |
|---|---|
| global static void bypass(SObjectType sObjectType) | Bypasses trigger actions for the specified SObject type. |
| global static void bypass(String sObjectName) | Bypasses trigger actions for the specified SObject type. |
| global static void bypass(String name, TRG_Base.BypassType type) | Bypasses a trigger by name, dispatching to the correct bypass set based on the bypass type. |
| global static void bypassAction(String actionClassName) | Bypasses a specific trigger action class by name. |
| global static void clearActionBypass(String actionClassName) | Clears the bypass for a specific trigger action class, allowing it to execute. |
| global static void clearAllActionBypasses() | Clears all action-level bypasses, allowing all trigger action classes to execute. |
| global static void clearAllBypasses() | Clears all SObject type bypasses, allowing all trigger actions to execute. |
| global static void clearAllBypasses(TRG_Base.BypassType type) | Clears all trigger bypasses, dispatching to the correct bypass set based on the bypass type. |
| global static void clearBypass(SObjectType sObjectType) | Clears the bypass for the specified SObject type, allowing trigger actions to execute. |
| global static void clearBypass(String sObjectName) | Clears the bypass for the specified SObject type, allowing trigger actions to execute. |
| global static void clearBypass(String name, TRG_Base.BypassType type) | Clears a trigger bypass by name, dispatching to the correct bypass set based on the bypass type. |
| global static Boolean isActionBypassed(String actionClassName) | Checks if a specific trigger action class is bypassed. |
| global static Boolean isBypassed(SObjectType sObjectType) | Checks if trigger actions are bypassed for the specified SObject type. |
| global static Boolean isBypassed(String sObjectName) | Checks if trigger actions are bypassed for the specified SObject type. |
| global static Boolean isBypassed(String name, TRG_Base.BypassType type) | Checks if a trigger is bypassed, dispatching to the correct bypass set based on the bypass type. |
| global static TRG_Base.BypassType resolveBypassType(String bypassTypeString) | Parses a bypass type string into the corresponding BypassType enum value. |
| global void run() | Executes the relevant trigger action based on the implemented interface and trigger context. |
| global static void setBypassReason(String reason) | Sets an optional transaction-scoped reason string that is attached to every subsequent bypass audit log entry. |
bypass
global static void bypass(SObjectType sObjectType)Bypasses trigger actions for the specified SObject type. Type-safe overload that accepts an SObjectType token instead of a string name.
Parameters
| Parameter | Type | Description |
|---|---|---|
sObjectType | SObjectType | The SObjectType token of the object to bypass. |
Example
TRG_Base.bypass(Account.SObjectType);
Boolean isBypassed = TRG_Base.isBypassed(Account.SObjectType); // trueglobal static void bypass(String sObjectName)Bypasses trigger actions for the specified SObject type.
Parameters
| Parameter | Type | Description |
|---|---|---|
sObjectName | String | The API name of the SObject type to bypass. |
Example
TRG_Base.bypass('Account');
Boolean isBypassed = TRG_Base.isBypassed('Account'); // trueglobal static void bypass(String name, TRG_Base.BypassType type)Bypasses a trigger by name, dispatching to the correct bypass set based on the bypass type.
Parameters
| Parameter | Type | Description |
|---|---|---|
name | String | The object API name or action class name to bypass |
type | TRG_Base.BypassType | The bypass type (OBJECT_NAME or CLASS_NAME) |
Example
TRG_Base.bypass('Account', TRG_Base.BypassType.OBJECT_NAME);
TRG_Base.bypass('TRG_SetDefaults', TRG_Base.BypassType.CLASS_NAME);bypassAction
global static void bypassAction(String actionClassName)Bypasses a specific trigger action class by name.
Parameters
| Parameter | Type | Description |
|---|---|---|
actionClassName | String | The class name of the trigger action to bypass. |
Example
TRG_Base.bypassAction('TRG_SetFoobarDefaults');
Boolean isBypassed = TRG_Base.isActionBypassed('TRG_SetFoobarDefaults'); // trueclearActionBypass
global static void clearActionBypass(String actionClassName)Clears the bypass for a specific trigger action class, allowing it to execute.
Parameters
| Parameter | Type | Description |
|---|---|---|
actionClassName | String | The class name of the trigger action to clear from bypass. |
Example
TRG_Base.bypassAction('TRG_SetFoobarDefaults');
TRG_Base.clearActionBypass('TRG_SetFoobarDefaults');
Boolean isBypassed = TRG_Base.isActionBypassed('TRG_SetFoobarDefaults'); // falseclearAllActionBypasses
global static void clearAllActionBypasses()Clears all action-level bypasses, allowing all trigger action classes to execute.
Example
TRG_Base.bypassAction('TRG_SetFoobarDefaults');
TRG_Base.bypassAction('TRG_ValidateFields');
TRG_Base.clearAllActionBypasses();
Boolean isBypassed = TRG_Base.isActionBypassed('TRG_SetFoobarDefaults'); // falseclearAllBypasses
global static void clearAllBypasses()Clears all SObject type bypasses, allowing all trigger actions to execute.
Example
TRG_Base.bypass('Account');
TRG_Base.bypass('Contact');
TRG_Base.clearAllBypasses();
Boolean isBypassed = TRG_Base.isBypassed('Account'); // falseglobal static void clearAllBypasses(TRG_Base.BypassType type)Clears all trigger bypasses, dispatching to the correct bypass set based on the bypass type.
Parameters
| Parameter | Type | Description |
|---|---|---|
type | TRG_Base.BypassType | The bypass type (OBJECT_NAME or CLASS_NAME) |
Example
TRG_Base.bypass('Account', TRG_Base.BypassType.OBJECT_NAME);
TRG_Base.clearAllBypasses(TRG_Base.BypassType.OBJECT_NAME);
Boolean isBypassed = TRG_Base.isBypassed('Account'); // falseclearBypass
global static void clearBypass(SObjectType sObjectType)Clears the bypass for the specified SObject type, allowing trigger actions to execute. Type-safe overload that accepts an SObjectType token instead of a string name.
Parameters
| Parameter | Type | Description |
|---|---|---|
sObjectType | SObjectType | The SObjectType token of the object to clear from bypass. |
Example
TRG_Base.bypass(Account.SObjectType);
TRG_Base.clearBypass(Account.SObjectType);
Boolean isBypassed = TRG_Base.isBypassed(Account.SObjectType); // falseglobal static void clearBypass(String sObjectName)Clears the bypass for the specified SObject type, allowing trigger actions to execute.
Parameters
| Parameter | Type | Description |
|---|---|---|
sObjectName | String | The API name of the SObject type to clear from bypass. |
Example
TRG_Base.bypass('Account');
TRG_Base.clearBypass('Account');
Boolean isBypassed = TRG_Base.isBypassed('Account'); // falseglobal static void clearBypass(String name, TRG_Base.BypassType type)Clears a trigger bypass by name, dispatching to the correct bypass set based on the bypass type.
Parameters
| Parameter | Type | Description |
|---|---|---|
name | String | The object API name or action class name to clear |
type | TRG_Base.BypassType | The bypass type (OBJECT_NAME or CLASS_NAME) |
Example
TRG_Base.bypass('Account', TRG_Base.BypassType.OBJECT_NAME);
TRG_Base.clearBypass('Account', TRG_Base.BypassType.OBJECT_NAME);
Boolean isBypassed = TRG_Base.isBypassed('Account'); // falseisActionBypassed
global static Boolean isActionBypassed(String actionClassName)Checks if a specific trigger action class is bypassed.
Parameters
| Parameter | Type | Description |
|---|---|---|
actionClassName | String | The class name of the trigger action to check. |
Returns Boolean — Boolean True if the action class is bypassed, false otherwise.
Example
TRG_Base.bypassAction('TRG_SetFoobarDefaults');
Boolean isBypassed = TRG_Base.isActionBypassed('TRG_SetFoobarDefaults'); // trueisBypassed
global static Boolean isBypassed(SObjectType sObjectType)Checks if trigger actions are bypassed for the specified SObject type. Type-safe overload that accepts an SObjectType token instead of a string name.
Parameters
| Parameter | Type | Description |
|---|---|---|
sObjectType | SObjectType | The SObjectType token of the object to check. |
Returns Boolean — Boolean True if the SObject type is bypassed, false otherwise.
Example
TRG_Base.bypass(Account.SObjectType);
Boolean isBypassed = TRG_Base.isBypassed(Account.SObjectType); // trueglobal static Boolean isBypassed(String sObjectName)Checks if trigger actions are bypassed for the specified SObject type.
Parameters
| Parameter | Type | Description |
|---|---|---|
sObjectName | String | The API name of the SObject type to check. |
Returns Boolean — Boolean True if the SObject type is bypassed, false otherwise.
Example
TRG_Base.bypass('Account');
Boolean isBypassed = TRG_Base.isBypassed('Account'); // trueglobal static Boolean isBypassed(String name, TRG_Base.BypassType type)Checks if a trigger is bypassed, dispatching to the correct bypass set based on the bypass type.
Parameters
| Parameter | Type | Description |
|---|---|---|
name | String | The object API name or action class name to check |
type | TRG_Base.BypassType | The bypass type (OBJECT_NAME or CLASS_NAME) |
Returns Boolean — True if bypassed
Example
TRG_Base.bypass('Account', TRG_Base.BypassType.OBJECT_NAME);
Boolean result = TRG_Base.isBypassed('Account', TRG_Base.BypassType.OBJECT_NAME); // trueresolveBypassType
global static TRG_Base.BypassType resolveBypassType(String bypassTypeString)Parses a bypass type string into the corresponding BypassType enum value. Wraps the standard valueOf call with a user-friendly error message on failure.
Parameters
| Parameter | Type | Description |
|---|---|---|
bypassTypeString | String | The string to parse (must be 'OBJECT_NAME' or 'CLASS_NAME') |
Returns TRG_Base.BypassType — The parsed BypassType enum value
Throws
| Exception | Description |
|---|---|
| System.Exception | If the string does not match a valid BypassType value |
Example
TRG_Base.BypassType type = TRG_Base.resolveBypassType('OBJECT_NAME');run
global void run()Executes the relevant trigger action based on the implemented interface and trigger context. This method checks the trigger operation and calls the appropriate interface method if implemented.
Throws
| Exception | Description |
|---|---|
| TypeException | If the class does not implement the required interface for the current context. |
| UTIL_Exceptions.IllegalStateException | If called outside of a trigger execution context. |
Example
public class CustomTriggerAction extends TRG_Base implements IF_Trigger.BeforeInsert
{
public void beforeInsert(List<SObject> newRecords)
{
for (SObject record : newRecords)
{
Account accountRecord = (Account)record;
accountRecord.Name = 'Updated Name';
}
}
}
// In a trigger context, calling run() will invoke beforeInsert for BEFORE_INSERTsetBypassReason
global static void setBypassReason(String reason)Sets an optional transaction-scoped reason string that is attached to every subsequent bypass audit log entry. Use before a batch of bypass calls to document the operational context (e.g., a data migration or incident response). Pass null or empty to clear.
Parameters
| Parameter | Type | Description |
|---|---|---|
reason | String | The reason string to record, or null to clear the previously set reason. |
Example
TRG_Base.setBypassReason('Customer data migration 2026-04-19');
TRG_Base.bypass(Account.SObjectType);
TRG_Base.bypass(Contact.SObjectType);Properties
| Property | Description |
|---|---|
| global TriggerOperation context | The current operation type being processed by the trigger action. |
| global String sObjectName | The API name of the SObject being processed by the trigger action. |
| global List<SObject> triggerNew | The list of "new" SObjects in the trigger context. |
| global List<SObject> triggerOld | The list of "old" SObjects in the trigger context. |
| global Map<Id, SObject> triggerOldMap | Map of "old" SObjects keyed by Id, for efficient field change detection in update contexts. |
context
@TestVisible global TriggerOperation contextType: TriggerOperation
The current operation type being processed by the trigger action.
sObjectName
@TestVisible global String sObjectNameType: String
The API name of the SObject being processed by the trigger action.
triggerNew
@TestVisible global List<SObject> triggerNewType: List
The list of "new" SObjects in the trigger context.
triggerOld
@TestVisible global List<SObject> triggerOldType: List
The list of "old" SObjects in the trigger context.
triggerOldMap
@TestVisible global Map<Id, SObject> triggerOldMapType: Map
Map of "old" SObjects keyed by Id, for efficient field change detection in update contexts.
Inner Classes
| Class | Description |
|---|---|
| BypassType | Indicates the type of trigger bypass being applied. |