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
JettaJetta 

How to pass List<sObject> to batch apex

Best Answer chosen by Jetta
sharathchandra thukkanisharathchandra thukkani
Through the constructor of the Batch class you can do that..i.e if your class is DemoBatch. In the batch class define a List and assign in the Constructor When you will create instanace of batch.. you can do something like..

global class DemoBatch implements Database.batchable<sObject>{
global List<sObject> myList;
global DemoBatch(List<sObject> objList){
myList = objList;
}

}
----------------
DemoBatch  db = new DemoBatch(objList);
db.executeBatch(db);

But you can pass the query string and you can query in the start method.

All Answers

sharathchandra thukkanisharathchandra thukkani
Through the constructor of the Batch class you can do that..i.e if your class is DemoBatch. In the batch class define a List and assign in the Constructor When you will create instanace of batch.. you can do something like..

global class DemoBatch implements Database.batchable<sObject>{
global List<sObject> myList;
global DemoBatch(List<sObject> objList){
myList = objList;
}

}
----------------
DemoBatch  db = new DemoBatch(objList);
db.executeBatch(db);

But you can pass the query string and you can query in the start method.
This was selected as the best answer
JettaJetta
I want to be able to pass this List to Execute method in batch for further processing. so how to be able to send this List as Scope to this method?
JettaJetta
Thanks Sharath. I got this working.