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
David SilvaDavid Silva 

How to pass all object from the salesforce to the batch class which is run asynchronously.

Hi,

I have to pass all the object in salesforce to the batch class for some activity.
How is it possible?
Regards,
 David.
 
Srinivas SSrinivas S
Hi David,

Please take a constructor -
global class BatchExample implements Database.Batchable<sObject>{

   Task tsk;
   global BatchExample(Task t){
	  tsk = new Task();
	  tsk = t;
   }

   global Database.QueryLocator start(Database.BatchableContext BC){
      return Database.getQueryLocator(query);
   }

   global void execute(Database.BatchableContext BC, List<sObject> scope){
     for(sobject s : scope){
     s.put(Field,Value); 
     }
     update scope;
    }

   global void finish(Database.BatchableContext BC){
   }
}

Invoke as follows -
BatchExample  be = new BatchExample(/*your task*/);
be.executeBatch(be);

--------------------
Thanks,
Srinivas
- Please mark as solution if your problem is resolved.