Exceptions/Challenges/Errors while using the Asynchronous Apex (Batch apex, Future method, Queueable Apex ,Schedule Apex) in Salesforce

In a Asynchronous call, the thread will not wait until it completes its tasks before proceeding to next. Instead it proceeds to next leaving it run in separate thread. In a Asynchronous call, the code runs in multiple threads which helps to do many tasks as background jobs.

To know more, check the following link:
Apex Exception Email in Salesforce
Set the email addresses that receive notifications when your Apex code encounters unhandled exceptions. Emails can be sent to your Salesforce org’s users and to external email addresses.

Salesforce sends two types of notification mails when potential issues with APEX code are detected:
APEX warning mails, which are sent when a class or trigger exceeds 50% of an APEX governor limit
APEX exception mails, which are sent when an unhandled exception occurs in a trigger or class

To setup, https://www.infallibletechie.com/2018/08/apex-exception-email-in-salesforce.html.

Platform event to handle Batch Apex:
Batch Apex classes can fire platform events when encountering an error or exception. Event records provide more granular tracking of errors than the Apex Jobs UI because they include the record IDs being processed, exception type, exception message, and stack trace. You can also incorporate custom handling and retry logic for failures. Clients listening on an event can tell how often it failed, which records were in scope at the time of failure, and other exception details. Events are also fired for Salesforce Platform internal errors and other “uncatchable” Apex exceptions like LimitExceptions that are caused by reaching governor limits.

The BatchApexErrorEvent object represents a platform event associated with a batch Apex class.
This object is available in API version 44.0 and later.
If the start, execute, or finish method of a batch Apex job encounters an unhandled exception, a BatchApexErrorEvent platform event is fired.

To fire a platform event, a batch Apex class declaration must implement the Database.RaisesPlatformEvents interface. 

Salesforce Reference Article:

No comments:

Post a Comment