Skip to content
Work in progress reference lib for BatchApexErrorEvent handling
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
config Initial commit Nov 19, 2018
force-app/main/default Small tweak to simplify sample code Nov 26, 2018
force-brf Comment update Nov 20, 2018
.forceignore Implemented batchable errors retry component Nov 20, 2018
LICENSE Create LICENSE Nov 21, 2018 Update Jan 21, 2019
sfdx-project.json Added component to utility bar Nov 20, 2018

force-brf - Batch Retry Framework

Reference lib for BatchApexErrorEvent handling. See blog here for more details.

In Winter’19 the BatchApexErrorEvent standard platform event was introduced. This event extends the above error reporting facilities with the ability to use Platform Events to listen (subscribe) to all job failures in variety of ways using clicks or code (clicks are not supported in Beta). The fields on the event give rich access to the exception type, stack trace, affected scope (records) and job ID. You can review a full list of the available fields here.

BatchApexErrorEvent. An event record provides more granular error tracking than the Apex Jobs UI. It includes the record IDs being processed, exception type, exception message, and stack trace. You can also incorporate custom handling and retry logic for failures. You can invoke custom Apex logic from any trigger on this type of event, so Apex developers can build functionality like custom logging or automated retry handling.


Deploy Setup

Run the following commands to deploy:-

sfdc force:source:push
sfdx force:user:permset:assign --permsetname Billing
sfdx force:user:permset:assign --permsetname brf_BatchRetryFramework

Data Setup

Run the following Apex code block to configure test data.

delete [select Id from Invoice__c];
delete [select Id from Order];
delete [select Id from Account];
delete [select Id from brf_BatchApexErrorLog__c];
Account orderAccount = new Account();
orderAccount.Name = 'Great customer!';
insert orderAccount;
List<Order> orders = new List<Order>();
for(Integer orderIdx = 0; orderIdx < 1000; orderIdx++) {
    Order order = new Order();
    order.Name = 'Ref:'+orderIdx;
    order.Status = 'Draft';
    order.EffectiveDate =;
    order.AccountId = orderAccount.Id;
insert orders;

Demo Steps

Perform the following steps to try out the framework with the sample app (included):-

  1. Open the Billing app
  2. Click the Orders tab and select the All list view
  3. Click the Invoice Generation button to start the job
  4. Open the Failed Jobs utlity bar and click Refresh button to see logged failures
  5. Use the Orders tab and Bad Orders list view to review bad records and delete one or more
  6. Open the Failed Jobs utility bar and click Retry action on the failed job
  7. Click the Refresh button to review remaining errors, repeat steps 5-7 until all clear!
You can’t perform that action at this time.