I have a batch class, In the start method of batch class, I'm calling another class which is returning the query string. When the batch executes I'm getting
System.QueryException: Variable does not exist: IdList exception
IdList, setOfAges and FromDate -> these are global variable.
I'm getting this error on return Database.getQueryLocator(query);
Query Class:
public with sharing class HelperClass{
public static String getQuery(List<Id> IdList, Set<integer> setOfAges, Date FromDate){
string query = 'Select Id, Name FROM ObjectA__c WHERE Service__c IN : IdList AND RecordType.Name = \'ABC\' AND Status__c <> \'Cancel\' AND Checkbox__c = FALSE AND (Age_Start_c IN : setOfAges OR Age_End__c IN : setOfAges) AND ((Start_Date__c <: FromDate AND End_Date__c >: FromDate) OR Start_Date__c >=: FromDate)';
}
}
Batch Class:
global Database.Querylocator start(Database.BatchableContext info){
system.debug('111... '+IdList);
system.debug('222.. '+setOfAges);
string query = HelperClass.getQuery(IdList, setOfAges, FromDate);
return Database.getQueryLocator(query);
}