I've noticed that Batch Apex classes are all global, and the dev console returns an error if you just try to do a public/private class.
My understanding is that a global class is visible to all other code, which would make sense if I'm making a generic Batch Apex processor class that feed calls to other classes to (if you can even do something like that). But what about when the batch process you want to perform is included completely within the body of the batch class - whats the point of having it global in that case?
Separately, I noticed in the first example given on the Using Batch Apex doc, the global variables have a 'final' modifier. I've been having difficulty finding the documentation on this modifier. Can anyone explain to me what it means, and what it's purpose is in this context?
Here's the example from the documentation:
global class UpdateAccountFields implements Database.Batchable<sObject>{
global final String Query;
global final String Entity;
global final String Field;
global final String Value;
global UpdateAccountFields(String q, String e, String f, String v){
Query=q; Entity=e; Field=f;Value=v;
}
global Database.QueryLocator start(Database.BatchableContext BC){
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC,
List<sObject> scope){
for(Sobject s : scope){s.put(Field,Value);
} update scope;
}
global void finish(Database.BatchableContext BC){
}
}