Newer Version Available
TriggerContext Class
Provides information about the platform event or change event trigger
that’s currently executing, such as how many times the trigger was retried due to the EventBus.RetryableException. Also, provides a method to
resume trigger executions.
Namespace
EventBus
TriggerContext Properties
The following are properties for TriggerContext.
lastError
Signature
public String lastError {get;}
Property Value
Type: String
Usage
The error message that this property returns is the message that was passed in when creating the EventBus.RetryableException exception, as follows.
1throw new EventBus.RetryableException(
2 'Condition is not met, so retrying the trigger again.');TriggerContext Methods
The following are methods for TriggerContext.
currentContext()
setResumeCheckpoint(resumeReplayId)
Sets a checkpoint in the event stream where the platform event trigger
resumes execution in a new invocation. Use this method to recover from limit and uncaught
exceptions, or to control the number of events processed in one trigger execution. When
calling this method, pass in the replay ID of the last successfully processed event message.
When the trigger stops execution before all events in Trigger.New are processed, either because of an uncaught exception or
intentionally, the trigger is invoked again. The new execution starts with the event message
in the stream after the one with the checkpointed Replay ID.
Signature
public void setResumeCheckpoint(String resumeReplayId)
Parameters
- resumeReplayId
- Type: String
- The replay ID of the last successfully processed platform event message, after which to resume processing in a new trigger execution context.
Return Value
Type: void
Usage
The method throws an EventBus.InvalidReplayIdException if the supplied Replay ID is not valid—the replay ID is not in the current trigger batch of events, in the Trigger.new list.
Example
This snippet shows how to call the method and pass in the replayId property of an event instance.
1EventBus.TriggerContext.currentContext().setResumeCheckpoint(event.replayId);