You need to sign in to do that
Don't have an account?

Multi-picklist variable binding in SOQL
Hi,
I'm attempting to bind a String into a SOQL query.
I get the following Error. expecting a left parentheses, found ':' (The line number refers to the SOQL query)
Any thoughts?
Thanks
public List<Contact> getPeople_In_Category(){ String Category_selected_str = "Translator"; people_list = [select c.id, c.name, c.phone, c.mobilePhone, c.email, c.title, c.account.name FROM Contact c WHERE c.Category__c INCLUDES :Category_selected_str LIMIT 100]; return people_list;
}
This might be repetitive, but I did want to post the revised version of your code snippet that I was able to compile:
String Category_selected_str = 'Translator'; List<Contact> people_list = [select c.id, c.name, c.phone, c.mobilePhone, c.email, c.title, c.account.name FROM Contact c WHERE c.Category__c INCLUDES (:Category_selected_str) LIMIT 100];
I changed the double-quotes to single-quotes. And I wrapped the INCLUDES clause with ().
All Answers
Try wrapping the includes clause with (). For example:
[select c.id, c.name, c.phone, c.mobilePhone, c.email, c.title, c.account.name FROM Contact c WHERE c.Category__c INCLUDES (:Category_selected_str) LIMIT 100]
This compiled and worked for me:
String hot = 'Hot'; Account a = [select id , name from account where Managed_Service__c includes (:hot)];
Thanks.
Youre suggestion may be correct. but isn't the problem. I've hard coded the string for the purpose of posting my code here. the string is actually populated by a VF picklist. I've verified that the string is indeed populated.
that's not the issue. as you can see, mine is a compile time error that disagrees with the variable binding.
Thanks anyway
This might be repetitive, but I did want to post the revised version of your code snippet that I was able to compile:
String Category_selected_str = 'Translator'; List<Contact> people_list = [select c.id, c.name, c.phone, c.mobilePhone, c.email, c.title, c.account.name FROM Contact c WHERE c.Category__c INCLUDES (:Category_selected_str) LIMIT 100];
I changed the double-quotes to single-quotes. And I wrapped the INCLUDES clause with ().
Folks,
Looks like we can only bind a String variable to a multi select column.I have a situation where I need to pass a set of string to the SOQL:
for e.g: Select a.Id,a.OwnerId from Account a
where a.Lead_Rating__c includes ('B','C')
Now when I try to construct the parameter and pass it dynamically, say for e.g:
String a = '\'B\'';
String b = '\'C\'';
leadRatingStr = a+','+b;
and do :
Select a.Id,a.OwnerId from Account a
where a.Lead_Rating__c includes (:leadRatingStr)
It doesnt work ... returns 0 rows where as the 1st query returned rows as expected. !! I simply dont understand. Any clue folks ?
Thanks
Try simplifying, and using only 'B' or only 'C'. this is just a test to see if either is working. if they do. then the use of , (comma) in the form ('B','C'), is perhaps malformed. consider reviewing the SOQL syntax.
Hope this helps.
Ben
You should separate values by ';' (semi-colon) and not ',' (comma) :
HTH,
Rup