Skip to content

snugsfbay/force-brf

 
 

Repository files navigation

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.

image

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 = System.today();
    order.AccountId = orderAccount.Id;
    orders.add(order);
}
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!

About

Work in progress reference lib for BatchApexErrorEvent handling

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Apex 86.6%
  • JavaScript 13.4%