What is the maximum number of items in a SOQL IN clause?

I think you are limited to the size of the query not exceeding 20,000 characters.

https://developer.salesforce.com/docs/atlas.en-us.salesforce_app_limits_cheatsheet.meta/salesforce_app_limits_cheatsheet/salesforce_app_limits_platform_soslsoql.htm

SOQL statements can't exceed 20,000 characters. For SOQL statements that exceed this maximum length, the API returns a MALFORMED_QUERY exception code ; no result rows are returned.

Maybe someone can weigh in on whether this applies to bound lists - if just comma-delimiting a bunch of IDs, one won't get more than about 1000 in there.

Edit: @sfdcfox has run an experiment and concluded bind variables do not contribute to query length.

Edit: It seems that when using bind variables, the number of items in an IN clause is determined by the amount of available heap space.


I don't think the accepted answer is correct. While the TOTAL length of a SOQL query must be less than 20,000 characters, the WHERE clause can only be 4,000 characters. And the IN clause is part of that 4,000 characters.

Therefore, the actual maximum length of the IN clause is less than 4,000 characters (because the field name and the string ' IN ' contribute to the 4,000 characters.

https://developer.salesforce.com/docs/atlas.en-us.salesforce_app_limits_cheatsheet.meta/salesforce_app_limits_cheatsheet/salesforce_app_limits_platform_soslsoql.htm

Tags:

Soql