Posts

Showing posts with the label Batch Apex

LinkedIn

Batch Apex - Better Exception Logging using Standard Platform Event - BatchApexErrorEvent

Image
BatchApexErrorEvent is a standard platform event introduced by Salesforce as part of API version 44.0. This mainly helps us to get the details of unhandled exceptions that happened from Batch Apex. To fire exception details to BatchApexErrorEvent, Batch Apex should implement  Database.RaisePlatformEvents interface. Let us cover below in detail: 1. BatchApexErrorEvent Details BatchApexErrorEvent holds below details: Let us implement a batch apex and see how BatchApexErrorEvent is helpful for tracking unhandled exceptions. 2. Sample Batch Apex Scenario Both Account and Contact has a field called Active__c which contains 2 values - Yes, No. When a parent Account is getting deactivated,ie Active=No, we need to mark all child contact's Active also as No. Batch Apex Logic Below Class is implemented to solve this. You can see that this class has implemented  Database.RaisePlatformEvents interface. public with sharing class Batch_ContactDeactivation implements Database.Batchable<...