Newer Version Available

This content describes an older version of this product. View Latest

BatchApexErrorEvent (Beta)

Represents a platform event associated with a batch Apex class. This object is available in API version 44.0 and later.

As a beta feature, Batch Apex Error Events is a preview and isn’t part of the “Services” under your master subscription agreement with Salesforce. Use this feature at your sole discretion, and make your purchase decisions only on the basis of generally available products and features. Salesforce doesn’t guarantee general availability of this feature within any particular time frame or at all, and we can discontinue it at any time. This feature is for evaluation purposes only, not for production use. It’s offered as is and isn’t supported, and Salesforce has no liability for any harm or damage arising out of or in connection with it. All restrictions, Salesforce reservation of rights, obligations concerning the Services, and terms for related Non-Salesforce Applications and Content apply equally to your use of this feature.

Note

Batch Apex classes can now opt in to 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()

Special Access Rules

Only the Salesforce Platform can fire this event, not Apex code or the API. Users with Customize Application Permission have read access.

Fields

Field Name Details
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 Message field is truncated due to the message exceeding the character limit.
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.
Message
Type
string
Properties
Nillable
Description
Exception message text.
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 are not 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.

Usage

BatchApexErrorEvent records are fired by batch Apex jobs that implement the Database.RaisesPlatformEvents interface and have unhandled Apex exceptions during processing. For more information, see the Apex Developer Guide.