You need to sign in to do that
Don't have an account?
minci
Another Batch Apex issue: class members.
I wrote somthing like this to check the way class fields are
behaving in Batch apex:
This code counts number of times execute method was called
For my surprise I saw that I get only 1 in the debug logs!
Code:
global class To_Bach implements Batchable{
global Integer _i;
global Bach(){
_i = 0;
}
global
global void execute(){
_i++;
System.debug('times visited '+i);
}
}
SO! How thies field behave?
What am I missing?
Thanks!
By default each execution of a batch apex job is considered a discrete transaction. To maintain state across transactions you have to declare the class as database.stateful.
I.E.