After seeing some discussion around static persistence across execution batches, I decided I should just test this out myself.
Turns out the Id's ARE tracked through each trigger batch.
Here's the test I ran:
Static Class
public with sharing class Tracker {
public static Integer runTime = 0;
public static List<Id> recordIds = new List<Id>();
}
Trigger
trigger StaticTestTrigger on Foo__c (after insert) {
Tracker.runTime++;
Tracker.recordIds.addAll(Trigger.newMap.keySet());
System.debug(Tracker.runTime);
System.debug(Tracker.recordIds.size());
}
Anonymous Apex:
List<Foo__c> foos = new List<Foo__c>();
for(Integer i = 0; i< 2000; i++){
foos.add(new Foo__c(Name = 'test'+i));
if(foos.size() == 200){
insert foos;
foos = new List<Foo__c>();
}
}
Output:
This obviously doesn't really answer the question I asked but I think should clear up confusion around statics across trigger batches.
Further testing:
Ran a batch of 460 records using the Salesforce Data Import wizard:
Again, it ran in a single execution context (statics were persisted):
Tracker.recordIds.addAll(Trigger.newMap.KeySet())
?