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

Multi pick list challenge ...
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
Two possiblities:
List<Account> a = [Select name from Account where name in ('test', 's')];
or
List<String> myList = new List<String>(); . . List<Account> a = [Select name from Account where name in :myList];
You have to add paranthesis as follows.
leadRatingStr = '('+a+','+b+')';
and try this.
Select a.Id,a.OwnerId from Account a where a.Lead_Rating__c in :leadRatingStr;
You could also do a dynamic query, and build the query string from a loop. This might need a little tweaking, but should get you started.
String querystr = 'Select a.Id,a.OwnerId from Account a where '; string querywhere=''; if(mymultiListstr.size==1){ querywhere = 'a.Lead_Rating__c = \''+x+'\''; }else{ for(String x : mymultiListstr){ querywhere = querywhere + 'a.Lead_Rating__c = \''+x+'\ or '; } querystr=querystr+querywhere.substring(1);//substring gets leading null off where clause Account[] accts = Database.query(querystr);
Srini,micwa - thanks for your responses. Actually we can only use includes() syntax( and not IN) when we are binding a variable to a multi pick list. Sorry if I was not clear on this part of the problem.
Jim - thanks & yes so far I see dynamic SOQL (building a query as a string and then using Database.query) as the only solution to this problem.
Thanks again folks.