11

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.

1 Answer 1

16

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.

4
  • 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, 2012 at 2:19
  • @LaceySnr-MattLacey, but wouldn't it be hard to capture the number of calls since they are on a rolling basis? Aug 10, 2012 at 18:22
  • Ah is it rolling? I thought it was per day — rolling would make more sense!
    – Matt Lacey
    Aug 11, 2012 at 1:31
  • 1
    Yes, it is rolling, though I believe it's updated on an hourly basis. Aug 11, 2012 at 6:54

You must log in to answer this question.

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