All Ideas

Idea Details

Post an Idea
310  Points
Open
Idea has been posted. Give it an upvote or downvote.

Create an exception class that throws warnings for governor limits

Apex & Visualforce

Governor limits are hard stops, and thus provide very little control to the developer. A previously submitted idea (marked as released) requested for better control over how those limits affect developers, and was marked as released in Winter '14. The idea resulted in flexible API limits, but this still doesn't help developers get where they need. Furthermore, checking Limits repeatedly is a waste of CPU time, and really shouldn't be the "responsibilty" of the developer. Developers should be able to simply write code and let the system notify them of any unusual problems.

What we need is the ability to shortcut our logic and gracefully exit when a limit is close at hand. This feature would not affect existing code, but would be useful in the future. Instead of inheriting from Exception, these classes would instead be a new base class of Warning. As part of a try-catch block, it would be a try-warn block, such as this:
try {
    Warnings.setCpuTime(1000);
    Warnings.setQueryRows(500);
    // perform some task that that should be done with at least 1 second left, 
    // and at least 500 rows free to query later;
} catch(Exception e) {
    // This might be a DML error, etc.
} warn(Warning w) {
    // We ran out of time or rows
    if(w.getType() == QueryRowWarning.class) {
        // Do something
    }
}
Warnings should be defined inside a try-catch block, and should expire at the end of the block. They should also be exposed as far up as the nearest try-warn block in whichever scope is appropriate. I would suggest that the finally block, if present, not be executed if a warning is issued; it should be safe to assume that if there were no warnings, then at least X amount of limits are left.

Merge Idea · Flag

  • Upvotes
  • Downvotes

Ideas

Apps

from AppExchange

Questions

Help us to keep IdeaExchange clean by pointing out overlapping ideas. We'll investigate your suggestion and merge the ideas if it makes sense.



 

 

Thanks for your merge suggestion. We will review it shortly and merge the ideas if applicable.

Salesforce takes abuse situations very seriously. Examples of abuse include but are not limited to posting of offensive language or fraudulent statements. To help us process your request as quickly as possible, please fill out the form below describing the situation. For privacy and security reasons, the final outcome of an abuse case may not be revealed to the person who reported it.


 

Thank you for your feedback. We take abuse seriously and will investigate this issue and take appropriate action.