Force-Framework

Mark Brennand

TriggerV1

global with sharing class TriggerV1
Description

Class defining the Trigger API available for public use.

The Subscriber interface defines the contract that implementations must provide to process events generated by the Trigger API.

Each Subscriber implementation must register itself with a Trigger metadata record.

See README for full details of the Trigger API.

Copyright (c) 2025 Mark Brennand, released under MIT License.

AuthorMark Brennand

  Properties

Operation
global enum Operation

The type of trigger operation that has fired.

Methods

  disable

global static void disable(final SObjectType type)
Description

Disables the subscribers for the given object type.

Parametertype: The object type whose subscribers are to be disabled.

  disable

global static void disable(final Type type)
Description

Disables the given Subscriber class.

No further events will be published to the associated subscriber.

Parametertype: The Subscriber class to disable.

  enable

global static void enable(final SObjectType type)
Description

Enables the subscribers for the given object type.

Parametertype: The object type whose subscribers are to be enabled.

  enable

global static void enable(final Type type)
Description

Enables the given Subscriber class.

Events will be published to the associated subscriber.

Parametertype: The Subscriber class to enable.

  isEnabled

global static Boolean isEnabled(final SObjectType type)
Description

Determines whether subscribers are enabled for the given object type.

Parametertype: The object type whose subscription status is to be checked.
ReturnsTrue if the subscribers are enabled.

  isEnabled

global static Boolean isEnabled(final Type type)
Description

Determines whether the given Subscriber class is enabled.

Parametertype: The Subscriber class to be checked.
ReturnsTrue if the Subscriber class is enabled.

  publish

global static void publish()
Description

Entry point for Trigger API.

This method must be called from the Apex Trigger.

An event representing the Trigger action is created and published to all the subscribers bound to the type of object associated with the Apex Trigger.

TriggerV1.APIException

global with sharing class APIException extends ForceFwException
Description

Exception thrown when a trigger operation fails.

TriggerV1.Event

global interface Event
Description

Event created by the trigger to represent the operation being performed.

The event is sent to all the Subscribers bound to the object.

Methods

  getOldValue

OptionalV1 getOldValue(final SObject record)
Description

Gets the old value of a record.

Parameterrecord: The record whose old value is required.
ReturnsThe old value of the record, or null if no old record found.

  getOldValues

OptionalV1 getOldValues()
Description

Gets all the old values registered.

ReturnsAll the old values.

  getOperation

TriggerV1.Operation getOperation()
Description

Yields the trigger operation being performed.

ReturnsThe operation being performed by the trigger.

  getRecords

Description

Yields the records passed to the trigger for processing.

Any records passed to an after trigger will have been cloned. This allows DML to be performed on them.

ReturnsThe records the trigger is processing.

  getRecursiveDepth

Integer getRecursiveDepth()
Description

Yields the maximum recursive depth for the trigger.

The recursive depth is the number of times the trigger has been called as a result of DML performed on the object associated with the trigger in trigger logic.

If the recursive depth returned is 0, no checks on the recursive depth are performed.

ReturnsThe maximum recursive depth for the trigger.

  hasOldValue

Boolean hasOldValue(final SObject record)
Description

Checks whether given record has an old value assigned.

Parameterrecord: The record whose old value is required.
ReturnsTrue if the record has an old value.

  isAfter

Boolean isAfter()
Description

Indicates whether the trigger is performing an after action.

ReturnsTrue if the trigger is performing an after action.

  isBefore

Boolean isBefore()
Description

Indicates whether the trigger is performing a before action.

ReturnsTrue if the trigger is performing a before action.

TriggerV1.Subscriber

global interface Subscriber
Description

Classes implementing this interface may register themselves for use of the Trigger API.

Methods

  onEvent

void onEvent(final TriggerV1.Event event)
Description

Method called by the Trigger API when a trigger fires.

The event argument encapsulates all the information for the trigger operation that has fired.

All the Subscriber implementations bound to the object whose trigger hss fired will have their onEvent method called.

Parameterevent: The trigger event.