[SalesForce] REQUEST_RUNNING_TOO_LONG

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.

Best Answer

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.

Related Topic