function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SanchSanch 

How do handle Batch Apex Error?

Hi there,

 

I am using the batch apex and I am trying to see how I can handle errors within the execute() method. I want to be able to find out which batch of records fail, so I could just run those records again in the future. Is there a way to do this? Please help. It's Urgent. Thanks.

 

Sanch

WizradWizrad

Create a custom object for logging failures from the batch.

 

Populate a field on it with the ids of records that failed.

 

Query for the custom object at some point and rerun on the ones that failed.

SanchSanch

Hi,

 

Thanks for your reply. But if I add the records that failed within the execute method and if the batch fails, it will roll it back so anything I insert will be rolled back. At the end,I won't have any records that failed in the custom object. Please let me know if there is any other way or if I am wrong with regard to what I mentioned earlier. Thanks.

 

Sanch