+ 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