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
beener3beener3 

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;

}

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
aalbertaalbert

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

aalbertaalbert

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]

 

bhbh
I've tried. doesn't work. Thanks!
aalbertaalbert

This compiled and worked for me:

 

String hot = 'Hot'; Account a = [select id , name from account where Managed_Service__c includes (:hot)];

 

Your string variable should have single quotes around it, not double quotes.
 

 

beenerbeener

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

aalbertaalbert

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 (). 

 

 

 

This was selected as the best answer
bhbh
It's wokring. thanks so much!
Arun BalaArun Bala

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

Message Edited by Arun Bala on 02-23-2009 05:38 PM
Message Edited by Arun Bala on 02-23-2009 05:39 PM
bhbh

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 

@altius_rup@altius_rup

You should separate values by ';' (semi-colon) and not ',' (comma) :

leadRatingStr1 = 'a;b';
leadRatingStr2 = 'c';
Select a.Id,a.OwnerId from Account a 
where a.Lead_Rating__c includes (:leadRatingStr1, :leadRatingStr2) 

 

HTH,

Rup