Back to Browse

Database.RaisesPlatformEvents - Report Errors using Platform Events from Batch Apex | BatchApexError

510 views
Apr 6, 2025
26:27

Aloha Trailblazers! 👋 In this comprehensive tutorial, we'll explore how to effectively handle errors in Salesforce Batch Apex using Platform Events and Apex Triggers. We'll report errors from Batch Apex using Database.RaisesPlatformEvents and we'll also learn how to capture and manage BatchApexErrorEvent using a trigger. In this video, you'll learn: ✅ Firing platform events (BatchApexErrorEvent) in case our batch class fails due to an exception. ✅ Implementing Apex Trigger to handle BatchApexErrorEvent. ✅ Debugging and analyzing logs to understand error details. ✅ Writing robust test classes for Batch classes implementing "Database.RaisedPlatformEvents" using "Test.getEventBus().deliver()". ✅ Achieving 100% code coverage in a few minutes using Agentforce for Developers. Chapters: 0:00 Introduction 0:30 Data & Metadata Setup 2:39 Batch class code explanation 6:51 Handle BatchApexErrorEvent (platform event) using a trigger 13:07 Demo - Executing Batch class and verifying errors 16:50 Understanding the BatchApexErrorEvent in detail using logs 18:55 Test class for Batch class implementing Database.RaisedPlatformEvents 22:12 Using Test.getEventBus().deliver() to ensure platform events are delivered in test methods 23:29 Using Agentforce to write another test method in order to increase code coverage to 100% 25:59 Wrapping Up Resources: 1. BatchApexErrorEvent: https://developer.salesforce.com/docs/atlas.en-us.platform_events.meta/platform_events/sforce_api_objects_batchapexerrorevent.htm 2. Firing Platform Events from Batch Apex: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_batch_platformevents.htm 3. Deliver Test Event Messages: https://developer.salesforce.com/docs/atlas.en-us.platform_events.meta/platform_events/platform_events_test_deliver.htm Other Playlists: 1. Coding with Confidence: The Fun Way to Learn Salesforce Apex: https://www.youtube.com/playlist?list=PLuL63vr-9xHzmee9NPhpowP2LiVF0oAE3 2. Apex Data Structures Tutorial: https://www.youtube.com/playlist?list=PLuL63vr-9xHxy2C7C6dYmn62T3eDwNnrR 3. Salesforce LWC Tutorial Series: https://www.youtube.com/playlist?list=PLuL63vr-9xHyaEARj8crQe3v2TBQa_Cs8

Download

0 formats

No download links available.

Database.RaisesPlatformEvents - Report Errors using Platform Events from Batch Apex | BatchApexError | NatokHD