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.
The following are properties for TriggerContext.
-
Read-only. The error message that the last thrown
EventBus.RetryableExceptioncontains. -
Read-only. The number of times the trigger was retried due to throwing the
EventBus.RetryableException.
Read-only. The error message that the last thrown EventBus.RetryableException contains.
public String lastError {get;}
Type: String
The error message that this property returns is the message that was passed in when creating the EventBus.RetryableException exception, as follows.
Read-only. The number of times the trigger was retried due to throwing the EventBus.RetryableException.
public Integer retries {get;}
Type: Integer
The following are methods for TriggerContext.
-
Returns an instance of the
EventBus.TriggerContextclass containing information about the currently executing trigger. -
Returns the replay ID that was set by
setResumeCheckpoint(). The returned value is the replay ID of the event message after which trigger processing resumes in a new trigger invocation. -
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.Neware 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.
Returns an instance of the EventBus.TriggerContext class containing information about the currently executing trigger.
public static eventbus.TriggerContext currentContext()
Type: EventBus.TriggerContext
Information about the currently executing trigger.
Returns the replay ID that was set by setResumeCheckpoint(). The returned value is the replay ID of the event message after which trigger processing resumes in a new trigger invocation.
public String getResumeCheckpoint()
Type: String
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.
public void setResumeCheckpoint(String resumeReplayId)
-
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.
Type: void
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.
This snippet shows how to call the method and pass in the replayId property of an event instance.