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.


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: http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_limits.htm

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 is catchable. is not catchable, and kills your script as a LimitException would.

  • 1
    Also, you could implement a custom setting and count the number of calls you've made in a given period. – Matt Lacey 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! – Matt Lacey Aug 11 '12 at 1:31
  • 1
    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 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.