You need to sign in to do that
Don't have an account?

How to pass multiple string value into a constructor of a batch apex at the run time ?
Hi All,
I have written a batch apex in a such a way that if string field we are passing then in query it should take other wise no.It is working for single string value but i need to make it work for multiple string values.
Constructor:
global StateBatch(String strfield,Date startDate, Date enddate) {
if(StartDate!= null && Enddate!= null){
query = 'select Id,Status_vod__c from State__c where Start_Date__c >=:startDate AND End_Date__c<=:endate';
if(String.isNotBlank(strfield)){
query += ' AND State__c IN (:strfield)' ;
}
}
}
Running in DEv console as
for multiple markets you run it as
StateBatch sb = new Statebatch ('\'United States of America\',\'United Kingdom\'',Date.newInstance(2019, 02, 13),Date.newInstance(2019, 02, 14));
database.executeBatch(sb);
Multiple values it is not taking .How will change to support multiple values.
Thanks in Advance
I have written a batch apex in a such a way that if string field we are passing then in query it should take other wise no.It is working for single string value but i need to make it work for multiple string values.
Constructor:
global StateBatch(String strfield,Date startDate, Date enddate) {
if(StartDate!= null && Enddate!= null){
query = 'select Id,Status_vod__c from State__c where Start_Date__c >=:startDate AND End_Date__c<=:endate';
if(String.isNotBlank(strfield)){
query += ' AND State__c IN (:strfield)' ;
}
}
}
Running in DEv console as
for multiple markets you run it as
StateBatch sb = new Statebatch ('\'United States of America\',\'United Kingdom\'',Date.newInstance(2019, 02, 13),Date.newInstance(2019, 02, 14));
database.executeBatch(sb);
Multiple values it is not taking .How will change to support multiple values.
Thanks in Advance
Change your constructor to accept the list of Strings
The Execute the batch as below
query = 'select Id,Status_vod__c from State__c where Start_Date__c >=:startDate AND End_Date__c<=:endate';