Spring 14 Limit change can break existing apps even when running previous version API

I’m looking for confirmation that what I’m seeing is real, and if this is a bug or an intentional breaking change.

Create the following test class:

public class TestLimits{
    public static testmethod void test1()
        for(Integer x = 0; x<100000; x++);
        system.debug(LoggingLevel.Info, 'Script limits: ' + Limits.getLimitScriptStatements() + ' Script Statements ' + limits.getScriptStatements());

On Winter 14 or earlier, you’ll get:

Script limits 200000 Script statements 0

On Spring 14 you’ll get:

Script limits 200000 Script statements 200000

Yes, I know that script limits no longer apply… but…

The problem is that any existing application that uses the limits statements to decide if it is safe to run (to avoid exceeding limits) will fail – as it thinks it has already exceeded limits.

Worse – this change impacts code that is running on older version APIs.

Thoughts? Comments? Help!!!


Josh Kaplan just tweeted a blog post explaining that this functionality is changing, and explains the issue quite well.

Essentially, Salesforce is going to change the return value of Limits.getScriptStatements() to be % of CPU limits used * script statement limit, as a way to continue to control flow, while giving a rough estimate of overall limits, leveraging the new CPU Limits.

Josh warns:

Please keep in mind that this number is not what it says it is. It is
NOT the number of statements. It is a representation of what the
statement count might have been, relative to your limit. It will, in
nearly every situation, undercount the number of statements done. The
intention with this mimicry is to allow your code to probably do what
it used to do without an immediate failure.

Source : Link , Question Author : kibitzer , Answer Author : Mikey

Leave a Comment