BatchApexErrorEvent

Notifies subscribers of errors and exceptions that occur during the execution of a batch Apex class. This object is available in API version 44.0 and later.

Batch Apex classes can fire platform events when encountering an error or exception. Clients listening to the event channel can tell how often it failed, which records were in scope at the time of failure, and other exception details.

Supported Calls 

describeSObjects()

Supported Subscribers 

SubscriberSupported?
Apex TriggersYes
FlowsYes
ProcessesYes
Pub/Sub APIYes
Streaming API (CometD)Yes

Subscription Channel 

/event/BatchApexErrorEvent

Special Access Rules 

Only the Salesforce Platform can fire this event; Apex code and the API can’t. Users with Customize Application Permission have read access.

Event Delivery Allocation Enforced 

Yes

Fields 

AsyncApexJobId 

Type: string

Properties: Nillable

Description: The AsyncApexJob record for the batch Apex job that fired this event.

DoesExceedJobScopeMaxLength 

Type: boolean

Properties: Defaulted on create

Description: True if the JobScope field is truncated due to the message exceeding the character limit.

EventUuid 

Type: string

Properties: Nillable

Description: A universally unique identifier (UUID) that identifies a platform event message. This field is available in API version 52.0 and later.

ExceptionType 

Type: string

Properties: Nillable

Description: The Apex exception type name. Internal platform errors are represented as the System.UnexpectedException type.

JobScope 

Type: textarea

Properties: Nillable

Description: The Record IDs that are in scope if the event was fired from the execute() method of a batch job. If the batch job uses custom iterators instead of sObjects, JobScope is the toString() representation of the iterable objects. Maximum length is 40,000 characters.

Message 

Type: string

Properties: Nillable

Description: Exception message text. Maximum length is 5,000 characters.

Phase 

Type: string

Properties: Nillable

Description: The phase of the batch job when it encountered an error.

Possible values: Values are START, EXECUTE, or FINISH.

ReplayId 

Type: string

Properties: Nillable

Description: Represents an ID value that is populated by the system and refers to the position of the event in the event stream. Replay ID values aren’t guaranteed to be contiguous for consecutive events. A subscriber can store a replay ID value and use it on resubscription to retrieve missed events that are within the retention window.

RequestId 

Type: string

Properties: Nillable

Description: The unique ID of the batch job that fired the event. Event monitoring customers can use this information to correlate the error with logging information.

StackTrace 

Type: string

Properties: Nillable

Description: The Apex stacktrace of the exception, if available. Maximum length is 5,000 characters.

Usage 

BatchApexErrorEvent messages are generated by batch Apex jobs that implement the Database.RaisesPlatformEvents interface and have unhandled Apex exceptions during processing. For more information, see the Firing Platform Events from Batch Apex.