2

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?

4
  • 1
    Can you make sure that the query which you are using in batch is returning you more than 24K records by running it in workbench query editor. This is just to make sure that your query is querying records that your are assuming – Kiran Machhewar Dec 6 '15 at 21:10
  • Are you able to resolve this @cloud lover ? – Salesforcesmarty Dec 6 '15 at 22:27
  • My guess would be you hit some sort of memory limit, thus aborting early. Did you try checking the logs for the last execute call? – sfdcfox Dec 6 '15 at 23:09
  • I am working and checking the logs :) Will update – cloudy-ritz Dec 7 '15 at 14:58
6

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:

  • the job does not appear like System.abortJob took place,
  • the remaining executes are discarded,
  • the finish() method does run,

If you are able to raise a case to Salesforce, they may be able to analyze to the extent:

"After processing N batches, one query in Class at line 46 has timed out as it is running for more than 2 minutes and the job was aborted there."

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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.