Skip to content

MetadataTriggerFramework

codefriar edited this page Oct 5, 2023 · 2 revisions

STATUS: ACTIVE

A metadata driven extension of the TriggerFramework class

Inheritance

TriggerFramework > MetadataTriggerFramework

Constructors

public MetadataTriggerFramework()

Constructor used by live triggers. Because this constructor makes live-use of a metadata query service that will query live metadata these two constructors are effectively un-testable without requiring you to insert custom metadata.

public MetadataTriggerFramework(List<SObject> triggerNew, List<SObject> triggerOld, TriggerOperation context)

Constructor used by Apex Triggers

Parameters

Param Description
triggerNew List the new version of the records
triggerOld List the old version of the records
context TriggerOperation the context of the trigger ie: after update

private MetadataTriggerFramework(MetadataTriggerQueryService mts)

TESTVISIBLE

Constructor used by unit tests

Parameters

Param Description
mts MetadataTriggerQueryService a potentially mocked version of the query service

Fields

private activeHandlerTriggerFramework

TESTVISIBLE

public bypassedHandlersSet<String>

Inherited

a set of handler names that are bypassed

private mtsMetadataTriggerQueryService

TESTVISIBLE

protected triggerContextTriggerContext

Inherited TESTVISIBLE

the current context of the trigger, override-able in tests

protected triggerNewList<SObject>

protected triggerOldList<SObject>

private triggersList<Metadata_Driven_Trigger__mdt>

TESTVISIBLE


Methods

public override void run()

SUPPRESSWARNINGS

Overrides the standard Run() method, which allows this metadata based trigger handler can be an incremental update / sit beside other trigger handlers classes that are directly invoked by a trigger

private void dispatch(TriggerFramework activeHandler)

method is responsible for calling delegated class methods on metadata specified classes.

Parameters

Param Description
activeHandler An instance of a class to have the appropriate method called on it. This class must implement the TriggerFramework interface.

protected Boolean standardValidationFails()

Inherited

A method to guard against invalid execution contexts

Returns

Type Description
Boolean true if the execution context is invalid or if this trigger handler is bypassed

public void setMaxLoopCount(Integer max)

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.

Parameters

Param Description
max A valid number (generally 1) of times you'd like to allow the trigger to run.

Example

In the context of a TriggerFramework class,
this.setMaxLoopCount(5);

public void clearMaxLoopCount()

Inherited

Allows developers to turn off the max loop count

Example

In the context of a TriggerFramework class,
this.clearMaxLoopCount();

public static void bypass(String handlerName)

Inherited

Allows developers to conditionally bypass (disable) other triggers that also implement this TriggerFramework

Parameters

Param Description
handlerName Class name (String) of the trigger handler to bypass

Example

TriggerFramework.bypass('AccountTriggerFramework');

public static void clearBypass(String handlerName)

Inherited

Removes a given trigger handler class name from the list of bypassed trigger handlers.

Parameters

Param Description
handlerName Handler class name to remove from the bypass list

Example

TriggerFramework.clearBypass('AccountTriggerFramework');

public static Boolean isBypassed(String handlerName)

Inherited

Allows developers to check whether a given trigger handler class is currently bypassed.

Parameters

Param Description
handlerName The name of the trigger handler class to check for

Returns

Type Description
Boolean Boolean

Example

TriggerFramework.isBypassed('AccountTriggerFramework');

public static void clearAllBypasses()

Inherited

removes all classes from the bypass list

Example

TriggerFramework.clearAllBypasses();

protected void addToLoopCount()

Inherited

TESTVISIBLE

private instance methods

protected String getHandlerName()

Inherited

TESTVISIBLE

Returns the string version of the handler class being invoked

Returns

Type Description
String String Name of the Handler

protected void beforeInsert()

Inherited

TESTVISIBLE

SUPPRESSWARNINGS

context methods

protected void beforeUpdate()

Inherited

TESTVISIBLE

SUPPRESSWARNINGS

Virtual method for the implementing class to override

protected void beforeDelete()

Inherited

TESTVISIBLE

SUPPRESSWARNINGS

Virtual method for the implementing class to override

protected void afterInsert()

Inherited

TESTVISIBLE

SUPPRESSWARNINGS

Virtual method for the implementing class to override

protected void afterUpdate()

Inherited

TESTVISIBLE

SUPPRESSWARNINGS

Virtual method for the implementing class to override

protected void afterDelete()

Inherited

TESTVISIBLE

SUPPRESSWARNINGS

Virtual method for the implementing class to override

protected void afterUndelete()

Inherited

TESTVISIBLE

SUPPRESSWARNINGS

Virtual method for the implementing class to override


Clone this wiki locally