Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to programatically detect if you have reached a governor limit?

For example, you can make 200 future calls per license per 24 hours. IF you hit that limit SFDC just starts to blow up on you. Is there some way to determine if you are under/over on the limit so you can react accordingly?

I'd prefer not performing an action if I'm over the limit rather than catching the exception and continuing to try in subsequent calls as it's a bit inefficient.

share|improve this question
up vote 13 down vote accepted

First of all, the exception thrown by hitting a limit, System.LimitException is uncatchable and means that your script will be killed, even if it happens inside a try/catch block. There is a class, Limits, that contains a number of static methods that allow you to check your governor limit consumption, see:

With that said, your example of @future calls per day is one of the limits that simultaneously is and isn't a governor limit as I believe it throws a System.AsyncException instead which should be catchable is not catchable, and kills your script as a LimitException would.

share|improve this answer
Also, you could implement a custom setting and count the number of calls you've made in a given period. – LaceySnr Aug 10 '12 at 2:19
@LaceySnr-MattLacey, but wouldn't it be hard to capture the number of calls since they are on a rolling basis? – Daniel Hoechst Aug 10 '12 at 18:22
Ah is it rolling? I thought it was per day — rolling would make more sense! – LaceySnr Aug 11 '12 at 1:31
Yes, it is rolling, though I believe it's updated on an hourly basis. – E.J. Wilburn Aug 11 '12 at 6:54

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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