Can I pass IDs from apex controller to apex batch class?
Can someone please show me some examples? Can't find in google search. I need just a reverse of below link. https://developer.salesforce.com/forums/?id=906F000000096KeIAI
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.
Sign up to join this communityCan I pass IDs from apex controller to apex batch class?
Can someone please show me some examples? Can't find in google search. I need just a reverse of below link. https://developer.salesforce.com/forums/?id=906F000000096KeIAI
For example, you have:
Base
inside the method calling the batch
Group grp = new Group(storeID);
Database.executeBatch(grp);
Group
public Group(*variable type* storeID)
{
passedID = storeID;
}
You can create variable in you batch class something like " global List<Id> currentId ;"
and from your main class set the value of this variable using class instance and then use this variable in your batch class. It works fine for you.
Here is a example
public class batchclass implements Database.Batchable<sObject>{
global List<Id> currentId ;
// Start Method
global Database.QueryLocator start(Database.BatchableContext BC){
return Database.getQueryLocator('SELECT Id,Name FROM Opportunity WHERE Id in :currentId and Type in : oppTypes ');
}
}
and your main class
public class mainclass {
public void somemethod() {
batchclass bat = new batchclass ();
bat.currentId = opptyId ;
database.executeBatch(bat,2) ;
}
}