TriggerV1 Description Copyright (c) 2025 Mark Brennand, released under MIT License . 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. Author Mark Brennand
Operation global enum Operation
The type of trigger operation that has fired.
ALL_OPERATIONS global static final Set<Operation> ALL_OPERATIONS
Definition a subscriber may use to indicate that it wishes to subscribe to all the trigger operations.
Methods Description Disables the subscribers for the given object type. Parameter type: The object type whose subscribers are to be disabled.
global static void disable(
Type type)
Description Disables the given Subscriber class. No further events will be published to the associated subscriber. Parameter type: The Subscriber class to disable.
Description Enables the subscribers for the given object type. Parameter type: The object type whose subscribers are to be enabled.
global static void enable(
Type type)
Description Enables the given Subscriber class. Events will be published to the associated subscriber. Parameter type: The Subscriber class to enable.
Description Determines whether subscribers are enabled for the given object type. Parameter type: The object type whose subscription status is to be checked. Returns True if the subscribers are enabled.
Description Determines whether the given Subscriber class is enabled. Parameter type: The Subscriber class to be checked. Returns True if the Subscriber class is enabled.
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.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 SObject getOldValue(SObject record)
Description Gets the old value of a record. Parameter record: The record whose old value is required. Returns The old value of the record, or null if no old record found.
List<SObject> getOldValues()
Description Gets all the old values registered. Returns All the old values.
Operation getOperation()
Description Yields the trigger operation being performed. Returns The operation being performed by the trigger.
List<SObject> 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. Returns The records the trigger is processing.
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. Returns The maximum recursive depth for the trigger.
Boolean hasOldValue(SObject record)
Description Checks whether given record has an old value assigned. Parameter record: The record whose old value is required. Returns True if the record has an old value.
Description Indicates whether the trigger is performing an after action. Returns True if the trigger is performing an after action.
Description Indicates whether the trigger is performing a before action. Returns True 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 Set<Operation> forOperations()
Description Returns the operations the subscriber will accept. Returns The operations.
void onEvent(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. Parameter event: The trigger event.