You need to sign in to do that
Don't have an account?
How apex get executed in Salesforce
i write a Batch apex.i write an execute method .which is using a static variable of another class.because it is shhared.any one can use it and change it.
public void execute(Database.BatchableContext BC, List<sObject> scope){
x=GMirror.x;
...........
...........
.........
y =GMirror.x;
}
i want to know each batch of 5 in my case will run in transaction or means at this time only this method is running nothing else or in other words i want to know if using another class's method execution in between time first statement execute
x=GMirror.x;
and second statement
y =GMirror.x;
its possible by another parallel execution of another class's method that these value of GMirror.x get changed ??
these execution this necessary that no one changed value of GMirror.x or value of GMirror.x can be changed by another parallel execution.Please clarify .
No, it is not possible for another transaction to modify a static variable that is in use in your transaction.
Static variables in apex are different to other programming languages (e.g. Java), due to the multi-tenant nature of the platform. In something like Java, when the JVM is created, the static variables are instantiated and are shared across the entire JVM. This wouldn't work in Salesforce, as there is effectively a single virtual machine for use by all clients. Static variables are instantiated when you commence a transaction and are removed once the transaction completes - they do no persist across transactions.
This is covered by a one-liner in the Apex Developer's Guide:
--- snip ---