+ Start a Discussion

Help In System.QueryException: unexpected token: '['

Hi I am using Dynamic query in Apex and I am facing this issue I have my debug logs:

What am I doing wrong?? This is my query string  --


10:17:09.075 (75325000)|USER_DEBUG|[86]|DEBUG|******Select Id,Name,Lookup__c from Record__c where Lookup__c IN  '[a02i00000012UOvAAM, a02i00000012UOfAAM]'


Bhawani SharmaBhawani Sharma
Use colon operator after Lookup__c IN

Lookup__c IN : SetIds

Thanks but WHEN I DO THIS

IN : [a02i00000012UOvAAM, a02i00000012UOfAAM]





 IN operator must be used with an iterable expression this error!!

Bhawani SharmaBhawani Sharma
Try one other option
Create a string using set in format
String ids = '(\'' + id1 + '\',\'' + id2 + '\')'

and then use in query
IN ids

Dont use colon this time
IN : (a02i00000012UOvAAM, a02i00000012UOfAAM)


use round bracket instead of square.

Bhawani SharmaBhawani Sharma
Did it help?
David Lee(China Developer)David Lee(China Developer)
Select Id,Name,Lookup__c from Record__c where Lookup__c IN ('a02i00000012UOvAAM', 'a02i00000012UOfAAM')