-
Notifications
You must be signed in to change notification settings - Fork 438
AccountTriggerHandler
Demonstrates how to construct a TriggerHandler using the trigger handler framework found in Shared Code/TriggerHandler.cls
Inheritance
TriggerHandler > AccountTriggerHandler
Group Trigger Recipes
See TriggerHandler
Constructor that sets class variables based on Trigger context vars
TESTVISIBLE
Inherited
TESTVISIBLE
Before Insert context method. Called automatically by the trigger framework this class extends.
Account[] accounts = new Account[]();
accounts.add(new Account(name='example 1'));
accounts.add(new Account(name='example 2'));
insert accounts;
after insert context method. Called automatically by the trigger framework this class extends
Account[] accounts = new Account[]();
accounts.add(new Account(name='example 1'));
accounts.add(new Account(name='example 2'));
insert accounts;
before update context method. Called automatically by the trigger framework this class extends
Account[] accounts = new Account[]();
accounts.add(new Account(name='example 1'));
accounts.add(new Account(name='example 2'));
insert accounts;
accounts[0].name += ' Updated';
update accounts;
SUPPRESSWARNINGS
after update context method. Called automatically by the trigger framework this class extends Note: this method contains a PMD false-positive report about CRUD checking before insert. However, trigger code is run in system mode, regardless of users, so it doesn't make sense to check for Account and Task permissions. This code is therefore only safe to execute in the context of a trigger.
Account[] accounts = new Account[]();
accounts.add(new Account(name='example 1'));
accounts.add(new Account(name='example 2'));
insert accounts;
accounts[0].name += ' Updated';
update accounts;
SUPPRESSWARNINGS
before delete context method. Called automatically by the trigger framework this class extends Note: this method contains a PMD false-positive report about CRUD checking before insert. However, trigger code is run in system mode, regardless of users, so it doesn't make sense to check for Account and Task permissions. This code is therefore only safe to execute in the context of a trigger.
Account[] accounts = new Account[]();
accounts.add(new Account(name='example 1'));
insert accounts;
delete accounts;
SUPPRESSWARNINGS
after delete context method. Called automatically by the trigger framework this class extends Note: this method contains a PMD false-positive report about CRUD checking before insert. However, trigger code is run in system mode, regardless of users, so it doesn't make sense to check for Account and Task permissions. This code is therefore only safe to execute in the context of a trigger.
Account[] accounts = new Account[]();
accounts.add(new Account(name='example 1'));
insert accounts;
delete accounts;
SUPPRESSWARNINGS
after undelete context method. Called automatically by the trigger framework this class extends Note: this method contains a PMD false-positive report about CRUD checking before insert. However, trigger code is run in system mode, regardless of users, so it doesn't make sense to check for Account and Task permissions. This code is therefore only safe to execute in the context of a trigger.
Account[] accounts = new Account[]();
accounts.add(new Account(name='example 1'));
insert accounts;
delete accounts;
undelete accounts;
Inherited
This is main brokering method that is called by the trigger. It's responsible for determining the proper context, and calling the correct method
AccountTriggerHandler.run();
Inherited
Allows developers to prevent trigger loops, or allow a limited number of them by setting the maximum number of times this trigger is called.
Param | Description |
---|---|
max |
A valid number (generally 1) of times you'd like to allow the trigger to run. |
In the context of a TriggerHandler class,
this.setMaxLoopCount(5);
Inherited
Allows developers to turn off the max loop count
In the context of a TriggerHandler class,
this.clearMaxLoopCount();
Inherited
Allows developers to conditionally bypass (disable) other triggers that also implement this triggerHandler
Param | Description |
---|---|
handlerName |
Class name (String) of the trigger handler to bypass |
TriggerHandler.bypass('AccountTriggerHandler');
Inherited
Removes a given trigger handler class name from the list of bypassed trigger handlers.
Param | Description |
---|---|
handlerName |
Handler class name to remove from the bypass list |
TriggerHandler.clearBypass('AccountTriggerHandler');
Inherited
Allows developers to check whether a given trigger handler class is currently bypassed.
Param | Description |
---|---|
handlerName |
The name of the trigger handler class to check for |
Type | Description |
---|---|
Boolean |
Boolean |
TriggerHandler.isBypassed('AccountTriggerHandler');
Inherited
removes all classes from the bypass list
Triggerhandler.clearAllBypasses();
Inherited
TESTVISIBLE
increment the loop count
Exception | Description |
---|---|
Throws |
loop count exception if the max loop count is reached |
Inherited
TESTVISIBLE
make sure this trigger should continue to run
Type | Description |
---|---|
Boolean |
Boolean |
Exception | Description |
---|---|
TriggerHandlerException |
thrown when executing outside of a trigger |
Custom exception class
Inheritance
AccountTriggerHandlerException