Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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
add comment

1 Answer

up vote 12 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: 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 should be catchable is not catchable, and kills your script as a LimitException would.

share|improve this answer
1  
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
1  
Yes, it is rolling, though I believe it's updated on an hourly basis. –  E.J. Wilburn Aug 11 '12 at 6:54
add comment

Your Answer

 
discard

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.