I created a batch that processes data based on certains parameters sent by the user and then sends the result via email.

But sometimes the parameters are too ambitious and the batch throws a System.LimitException.

Is there a way to catch it in order to send an email to notify the user of the error ?

  • could you post your code?
    – m Peixoto
    Commented Dec 12, 2019 at 13:35

2 Answers 2


From Salesforce help

Some special types of built-in exceptions can’t be caught. Those exceptions are associated with critical situations in the Lightning Platform. These situations require the abortion of code execution and don’t allow for execution to resume through exception handling. One such exception is the limit exception (System.LimitException) that the runtime throws if a governor limit has been exceeded, such as when the maximum number of SOQL queries issued has been exceeded.

You best bet is going to be something along the lines of inspecting the input parameters and filtering the "Too-Ambitious" ones out before processing.


Limit exceptions are not able to be caught and handled. I don't think it's called out very clearly in the documentation, but it is in there.

From the Exception Classes and Built-In Exceptions page

LimitException    A governor limit has been exceeded. This exception can’t be caught.

The closest thing you'd be able to do is monitor the various governor limits with the Limits class (e.g. Limits.getCpuTime()).

The simple case would be voluntarily terminating your work if one of the limit usages gets too high (e.g. You've used 95 SOQL queries, and you know you'd try to use at least 6 more queries).

A more complex case would be monitoring how much of your target limits are used by a single record that you're processing, and then using that to automatically determine if you have enough of a given limit remaining to process another record.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .