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
JeffreyStevensJeffreyStevens 

APEX Batch getQueryLocator with queryString using the IN clause

How is the IN clause used with a set<> in batch and getQueryLocator?
 
I have this code:
 
// (in the Start method of a batch class....)  
set<id> accountIDs = new set<id>(); // This is already populated... 
queryString = 'SELECT id,name FROM Account WHERE id IN :accountIDs'; 
return Database.getQueryLocator(queryString);

Is this the correct syntax?  How do you actually use a set<> (or .keyset() from a map) in a queryString that get's passed to the getQueryLocator?
AnkaiahAnkaiah (Salesforce Developers) 
Hi,

Its correct.
queryString = 'SELECT id,name FROM Account WHERE id IN :accountIDs';

Refer the below link.
https://salesforce.stackexchange.com/questions/339024/reference-setid-in-the-where-clause-of-a-dynamic-soql-in-batch-class

if this information helps, Please mark it as best answer.

Thanks!!