Find your content:

Search form

You are here

Detecting governor limits through apex

 
Share

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.


Attribution to: Ryan Elkins

Possible Suggestion/Solution #1

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.


Attribution to: ca_peterson
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/291

My Block Status

My Block Content