Posts

Showing posts with the label Batch apex

Salesforce Fact #856 | BatchApexErrorEvent subscribe using flow

BatchApexErrorEvent  is a built in event which is triggered for unhandled exception in batch class. In order to raise platform events from batch apex, we need to implement Database.RaisesPlatformEvents interface. We can subscribe to BatchApexErrorEvents using platform event type triggered flow. Reference:  https://developer.salesforce.com/docs/atlas.en-us.platform_events.meta/platform_events/sforce_api_objects_batchapexerrorevent.htm

Salesforce Fact #627 | Passing list of Sobject across batch apex

Image
Suppose we need to pass List<Sobject> records from one batch apex to another. We can call the 2nd batch from finish method of the 1st one and pass the list of records. In this example, we are creating 5 account records in batch1 and then passing the records to batch2 from the finish method of 1st batch. In this case, we need to use the  Iterable<SObject> type and the 1st batch needs to implement Database.Stateful interface to retain the value. Attached are the screenshots.