You need to sign in to do that
Don't have an account?
Variable not available in different class.
I have two global classes. In the CreateAndModify class i have an execute functions which has a for loop which calls a processRecord method of my other class i.e CreateAndModifyProcessor. The problem is that there is a collection of list declared in my first class which i cannot access in the second class. Is there any way to do it and is it even a good ides to do it this way ?..
global class CreateAndModify implements
Database.Batchable<sObject>, Database.Stateful{
global void execute(
Database.BatchableContext BC,
List<sObject> listObj){
list <Account__c> inAcc = new list<Account__c>();
for (sObject lo : listObj){
processor.processRecord(lo);
}
insert inAcc; // The list object which i am modifying in the processRecord function has to be added to the database. So, is it
// a good idea to add/populate the list in other function of other class
}
global class CreateAndModifyProcessor {
global void processRecord(sObject listObj){
Unprocessed_Agreement__c temp = (Unprocessed_Agreement__c)listObj;
Account__c tempAcc = new Account__c();
inAcc.add(tempAcc); // This line throws an error
}
}
my 2 cents: passing "inAcc" as an argument would help and, I would suggest to take a look at this:
http://blogs.developerforce.com/developer-relations/2012/05/passing-parameters-by-reference-and-by-value-in-apex.html