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
Steven ShenSteven Shen 

How to calculate the length of SOQL where statement if we bind variables

Hi all,
A question really makes me confused recently, could anyone help me?
As we known, the default maximum length of SOQL WHERE clause is 4000 characters. I want to know Apex will hwo to calculate the length of SOQL WHERE clause when we bind variables in it, especially collection type variable, such as List and Set type.
For example, we define a list variable like List<Integer> list1 = new List<Integer>{1, 2, 3, 4, 5, 6, 7};

SOQL1: SELECT XXX FROM XXX WHERE XXX IN: list1
SOQL2: SELECT XXX FROM XXX WHERE XXX IN (1, 2, 3, 4, 5, 6, 7)

SOQL1 equals SOQL2, what about the length?

Steven
devedeve
Hi Steven,

You can check this link for the explation https://salesforce.stackexchange.com/questions/25719/what-is-the-maximum-number-of-items-in-a-soql-in-clause
Chandra@AtlantaChandra@Atlanta
Steven,
though there is not documented pre-defined limit set for IN clause, there is a limit in on how many bytes it allows below are some limitations

1. you entire where clause cannot exceed certain bytes
2. the IN clause will also more than 1000 values but approx upto 7000 bytes

I hope this helpful

"Appreciate your feedback"

 
Steven ShenSteven Shen
Hi all,
Thank you for your answers.
I built a SOQL statement with in (1, 2, 3, 4, 5, 6, 7,.....,99999) array.
It's a long long statement and I thought it would hit the max charachters limit but it didn't.
Really strange!

Steven
Chandra@AtlantaChandra@Atlanta
Steven,

when you write and SOQL and with "IN" clause and start putting the numbers like  IN (1,2,3,4,.....1300...1400....)  you will hit the limit and get an error. so there is limit on IN clause and where clause by itself.

There is standard error like limit exceeded with xml tags included in the error message.

I hope this is helpful.

"Appreciate a Like, if not best Answer"