I have an apex batch job, to query all closed cases older than 13 months. I have implemented the Stateful interface to that I can accumulate all the rows over the several batches that will execute.
However, only a portion of the batches will process. There should be more than 96,000 records, but I receive only around 24000 records when the finish method is executed. If I set the scope to 2000,
the AsyncApexJob shows only 11 or 12 of the 48 total batch jobs. How can I get the rest of the batches to execute?
Whats the possible cause and how to find that?
Best Answer
Rarely, batch jobs do fail to execute with no error message.
One of the modes that causes this, can be when a SOQL query cannot be executed within the time limits. For example, a particularly non-selective query happening during the batch
execute()
method will cause the rest of the job to fail to execute. That's not "abort", but actually fail to execute.The really kooky details are:
System.abortJob
took place,finish()
method does run,If you are able to raise a case to Salesforce, they may be able to analyze to the extent:
One time during API 34.0, they were also able to confirm that there is some erroneous behaviour around the UI display of the AsyncApexJob which should show
Failed
but doesn't.Perhaps by exceeding the heap size with the
Database.Stateful
it has incurred a similar failure mode, where the whole job has to be trashed rather than continuing because of memory limits?