0

First error: [REQUEST_RUNNING_TOO_LONG] Your request was running for too long, and has been stopped.

I was looking at What causes REQUEST_RUNNING_TOO_LONG test errors?. I was guessing because its a governor limit error the code terminates immediately and the exception cannot be caught!

In that case how does it behave in batch class?

Below is a hypothetical scenario:

A batch class is processing let's say 100,000 records with 1000 records per job, If my Job number 5 hits with the above error, Does it only terminate Job 5 or entire Batch?

If it only terminates Job5 (as each job is a separate transaction),how would i know about the errors in Job5 in the subsequent job(Job6) because it terminated unexpectedly? What is the best way to deal with this error in a batch class.

3

I was looking at What causes REQUEST_RUNNING_TOO_LONG test errors?. I was guessing because its a governor limit error the code terminates and the exception cannot be caught!

No, it's actually a system limit. Unlike governor limits, which can be temporarily avoided, this is a hard limit which can't be avoided or caught at all.

In that case how does it behave in batch class?

It is normally impossible to get this error in a batch class. There are some bugs that you can use to trick the system into causing this error, but under normal circumstances, writing normal code, you can't get this error.

A batch class is processing let's say 100,000 records with 1000 records per job, If my Job number 5 hits with the above error, Does it only terminate Job 5 or entire Batch?

It won't hit this error, as above. In the more general sense, a single chunk that fails won't abort the remaining chunks (the batch will continue to run). The exception to this is if you get a fatal exception during the start method, in which case, no chunks will run.

If it only terminates Job5 (as each job is a separate transaction),how would i know about the errors in Job5 in the subsequent job(Job6) because it terminated unexpectedly?

The only information you will get if a governor limit is reached is an error on the parent AsyncApexJob, in the ExtendedStatus field. Only the first error is reported, however. You can also determine the total number of fatal errors via the NumberOfErrors field.

What is the best way to deal with this error in a batch class.

There's really not much you can do about governor limits; once you're terminated, you're terminated. The best way to handle this situation is to not get in that situation in the first place. That might mean reducing the batch size, optimizing code, extending execution time with Queueable, or perhaps even implementing a chained Queueable instead of using Batchable. The situation will change depending on the reason for the exception. Too many DML statements is a different problem than a Too much CPU time problem.

  • +1 I have my own custom rollup mechanism that rollsup entire batch if any errors in previous jobs, so based on your comments i can check the error fields of asyncapexjob on my previous jobs alongside with the dml result errors to run the subsequent batches! does this makes sense? – codeyinthecloud Sep 4 '18 at 16:51
  • Based on your last comment Too many DML statements is a different problem than a Too much CPU time problem. This is not really a CPU timeout for me to optimize my code right? – codeyinthecloud Sep 4 '18 at 16:56
  • 1
    @codeyinthecloud I'm not sure what problem you're trying to solve here, though. Your code should not have fatal exceptions, and if it does, you should not be able to expect to handle them. Always use row-locking statements if necessary, always use correct try-catch blocks, partial DML statements, etc. If you're reaching governor limits because of whatever it is you wrote, then you have an optimization problem. – sfdcfox Sep 4 '18 at 17:05

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.