You need to sign in to do that
Don't have an account?
Batch APEX Query IN clause
I have a batch process setup that could process upwards of 300,000 contact records. Do to governor limits, I've setup my code to use batch apex. All my code is working except for the query call.
TerritoryRefreshBatch trb = new TerritoryRefreshBatch(); trb.query = 'SELECT Id, AccountId, MailingPostalCode, IM_Territory__c, EM_Territory__c, RatingOverride__c ' + 'FROM Contact ' + 'WHERE MailingPostalCode IN \'' + zCodes + '\'' + 'AND RecordTypeId IN \'' + rtIds + '\''; string batchId = Database.executeBatch(trb);
Syntactically, it's saves but when I exectuce the batch I get a "First error: unexpected token: '{012d0000000Ssj3AAC, 012d0000000Ssj8AAC}'". That token is my set<string> of values I need for the dynamic query.
If I modify my query to pull a specific record, everything processes fine. So, my question is, how do I structure my query string when using the "IN" clause?
@Avin Thank you! That got me close enough to get it working. I used what you gave me and then just had to define the two variables in the controller and set them.
First few lines of the controller:
All Answers
try this
trb.query = 'SELECT Id, AccountId, MailingPostalCode, IM_Territory__c, EM_Territory__c, RatingOverride__c FROM Contact WHERE MailingPostalCode IN: zCodes AND RecordTypeId IN: rtIds';
@Avin Thank you! That got me close enough to get it working. I used what you gave me and then just had to define the two variables in the controller and set them.
First few lines of the controller: