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

Oracle has a limit of 1000 items for its IN clause. Is there a similar limit in SOQL? The SF documentation on the IN clause does not mention any limit. To clarify the definition of an item, the following example has 2 items in its IN clause:

SELECT Name FROM Widget__c
WHERE Name IN ('Ring', 'Flange')
  • the above code was taken from the linked SF documentation.

Answer

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.

Attribution
Source : Link , Question Author : edgartheunready , Answer Author : anothermh

Leave a Comment