You need to sign in to do that
Don't have an account?
Arek S.
Format of SOQL Query using IN clause
I'm sending a query to SalesForce (using the SOAP API) that includes an IN clause, however, I keep getting a MALFORMED_QUERY error. Could someone point me in the right direction of what the query syntax is when using the IN clause? I've tried the following without success (the ids are made up in these examples):
SELECT Id FROM Lead WHERE Id IN {'000000000000000','111111111111111'}
SELECT Id FROM Lead WHERE Id IN '0000000000000','111111111111111'
Thanks.
You're close
select id from lead where id in ('00Q3000000zLxkFEAS', '00Q3000000eODvUEAW')
All Answers
You're close
select id from lead where id in ('00Q3000000zLxkFEAS', '00Q3000000eODvUEAW')
IN allows you to specify a comma separated list in the WHERE clause to match across multiple matches. Instead of WHERE Name = 'Olivia' you could check for WHERE Name IN ('Olivia','Kyle','John') and it will give results for all 3.
The major benefit of this approach, quite apart from the fact that it avoids the need to generate the "('id1', 'id2', ...)" text, is that the binding automatically avoids SOQL injection issues. If you take values from user input and that user knows how that value might be used, they could include some SOQL of their own by inserting a single quote in the value. When you then build the string, their single quote would be parsed as the end of the string and their text following that quote becomes some SOQL. I accept this isn't so big an issue here, since you are looking at Id strings and these don't include quotes - but you should get in the habit and stick with it.