Using inline binding circumvents the normal character restrictions of an SOQL statement; as long as you don't exceed the heap size limit, you can include as many values as you like in the list. Here's an execute anonymous script that will query for 161,448 (non-existent) unique Id values:
id[] idlist = new id[0];
String[] keys = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'.split('');
for(integer a = 0; a < 42; a++) {
for(integer b = 0; b < 62; b++) {
for(integer c = 0; c < 62; c++) {
idlist.add('001000000000'+keys[a]+keys[b]+keys[c]);
}
}
}
// Following query will run fine with 161k Id values
Account[] accounts1 = [select id from account where id = :idlist];
// As will this one
Account[] accounts2 = database.query('select id from account where id = :idlist');
This code essentially generates a query that would require 3,500,000 SOQL characters (minimum), yet doesn't run into any particular limits.
Eventually, depending on what you're doing, you'll run into either heap limits, maximum payload size limits, etc.
When practical, sort your results by Id or CreatedDate, and use that as a simple filter instead. You can read more about doing that in this answer.
Database.query()with the text from your query, would it fail? – battery.cord Apr 13 '18 at 13:43database.query('select id from account where id = :idlist')(will not exceed character limits) ---database.query('select id from account where id IN (\''+string.join(idlist,'\',\'')+'\')');(normal 20k/4k rules apply). – sfdcfox Apr 13 '18 at 13:46