[SalesForce] API and static variables reset

As per this documentation
Trigger

Note that static variable values are reset between API batches, but
governor limits are not. Do not use static variables to track state
information between API batches

I have this trigger

trigger apextrigger on Account (before insert) {

    system.debug('Counter is'+ myclassfortrigger.incrementcounter());
    system.debug(Trigger.new.size()+'MYTriggernew');
}

and class

public class myclassfortrigger{
public static integer counter = 0;      
    public static integer incrementcounter()
    {

        counter = counter + 1;
        return counter;
    }

    }

when i pass say 500 record to this,via Dataloader,Bulk api enabled
and batch size is made as 500

In my debug log i can see one log for this(as expected)
and inside in my debug statements i could see static variables are not getting reset

it shows

16:17:39.128 (128115231)|USER_DEBUG|[3]|DEBUG|Counter is1
16:17:40.795 (1795145037)|USER_DEBUG|[3]|DEBUG|Counter is2

As it uses API batches i thought as per documentation static variables would have got reset?

Where am i going worng?

Best Answer

This documentation appears to be bogus. The entire quote is:

For Apex saved using Salesforce.com API version 20.0 or earlier, if an API call causes a trigger to fire, the chunk of 200 records to process is further split into chunks of 100 records. For Apex saved using Salesforce.com API version 21.0 and later, no further splits of API chunks occur. Note that static variable values are reset between API batches, but governor limits are not. Do not use static variables to track state information between API batches.

However, during testing various sizes and API modes, I was never able to achieve a trigger size of 100. Even running in v10.0 mode, the trigger code was still accepting 200 records at a time. Also, static variables within a class were preserved in Bulk API mode, despite this documentation. I suspect that while this may have been true in the past, this behavior is no longer true, and the documentation was simply never updated to reflect this change in behavior. That said, however, you should never trust any static variables to exist across non-recursive trigger contexts (e.g. it's okay to use a variable to prevent recursion, but not to track state between triggers); sufficiently large Bulk API requests, for example, may lose the static variable data at any point during the transaction.