function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
salmanmanekiasalmanmanekia 

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
}
}

sf.azzola.01sf.azzola.01

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