Create an exception class that throws warnings for governor limits - Ideas - Salesforce Trailblazer Community
Trailblazer Community

All Ideas

Idea Details

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

Create an exception class that throws warnings for governor limits

Development (Apex, LWC & VF)

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 {
    // 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



from AppExchange






