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
SidharthSidharth 

Apex batch retry on failure

I have apex batch scheduled to run daily.This batch query sometime timesout (First error: [QUERY_TIMEOUT] Your query request was running for too long).

Is there any wayto retry the batch at the same time ?

The problem is, this type of error, doesnot go in the try/catch, and also no FInish method is called. So i am not sure how to detect this batch failure and rerun it. 

Sid
Abhi_TripathiAbhi_Tripathi
If you are getting timeout error, so you should have limit in the SOQL query as well as where clause which fetches the precise data that you want.

Calling the batch write after the same time, will put it in loop, it will end up having another error.
So best you can do is to update the processed data with some indicator, that this record has been updated in the batch.