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 an sObject and a criteria to the apex batch class?

Hi all,

How to pass an sObject and a criteria to the apex batch class ?
It is possible to do in the constructor of the class rt.
CloudGeekCloudGeek
Hello Daid,

Looks like you are trying to implement similar to this :
https://developer.salesforce.com/forums/?id=906F0000000AtLQIA0

You can try something like :
//Suppose your sObject is Account
Account acc = new Account(Name = 'Test Account');
​insert acc;
​
DeleteJob dj = new DeleteJob(acc,2);  //object and years passed to your constructor
dj.executeBatch(dj);