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
thekid12345thekid12345 

Is there any way to call a class that is already created and reference it in a batch class so that the class is ran on a nightly basis?

For Example, below is my class that I want to reference in the batch class.  Is there a way where I can schedule the class called Test and reference it in the Batch class?
public class Test{
//Code to do updates
}
global class ExampleBatchClass implements Database.Batchable<sObject>{

        global ExampleBatchClass(){
                   // Batch Constructor
        }
       
        // Start Method
        global Database.QueryLocator start(Database.BatchableContext BC){
         return Database.getQueryLocator(query);
        }
      
      // Execute Logic
       global void execute(Database.BatchableContext BC, List<sObject>scope){
              // Logic to be Executed batch wise      
     
       }
     
       global void finish(Database.BatchableContext BC){
            // Logic to be Executed at finish
       }
    }


 
Raj VakatiRaj Vakati
Yes ..  Please find the pseudo code here 
 
global class ExampleBatchClass implements Database.Batchable<sObject>{

String query = [Select Id , Name ,Description  from account ];
        global ExampleBatchClass(){
                   // Batch Constructor
        }
       
        // Start Method
        global Database.QueryLocator start(Database.BatchableContext BC){
         return Database.getQueryLocator(query);
        }
      
      // Execute Logic
       global void execute(Database.BatchableContext BC, List<sObject>scope){
              // Logic to be Executed batch wise      
     List<Account> accs = (List<Account>)scope ; 
	 Test.update(accs)
	 
       }
     
       global void finish(Database.BatchableContext BC){
            // Logic to be Executed at finish
       }
    }
	
	
	
	
public class Test{
//Code to do updates
public Test( ){
	
}

public static  void update(List<account> acc){
	for(Account a : acc){
		a.description ='Update frmo the class' ;
	}
	
}


}



 
thekid12345thekid12345
What happens if there are multiple queries in my class?  How do I reference them in the batch class?
Raj VakatiRaj Vakati
You can define the different methods or constructor to accept those queries 
thekid12345thekid12345
Can you show an example, please?