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
Chandra Sekhar CH N VChandra Sekhar CH N V 

Like operator substitute for multi select picklist field

I have a query where I am querying a picklist field to gte specific set of values -
 
WHERE <picklist field> like '%value%'

I have now changed the data type to multi select and query gets failed. 

How to replace the original query so that I can get only s specific set of values from the multi select picklist.
Ajay K DubediAjay K Dubedi
Hi Chandra Sekhar,
I think that like operator is not supported with multi-select picklist in salesforce. You can just go through the link for the detailed knowledge of which operator to be used with the multi-select picklist.
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_querying_multiselect_picklists.htm

Thanks.
Shailendra Singh ParmarShailendra Singh Parmar
Hi Chandra,
Yes as Ajay said that like is only supported for text fields so you can't directly use like for multiselect. Think about creating formula fields or other fields that is populated by workflow then use like operator.

Thanks!
Nitin PaliwalNitin Paliwal
Hi,
You can use Includes operator.
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_querying_multiselect_picklists.htm

SELECT Id, MSP1__c from CustObj__c WHERE MSP1__c includes ('AAA;BBB','CCC')

Thanks
Nitin
Chandra Sekhar CH N VChandra Sekhar CH N V
Thanks for the replies.

@ Shailendra - I'm infact using this query in a class so I don't wont to go for an workflow/another formula field again. 

@Nitin,, - the query searches for exact match of values if I am not wrong. But my requirement is slight different here. I am actually trying to get specific values from the list of available picklist values which is a multiselect field at the object level. Ex- suppose I have values A,B,C,AA,ABC, then I want to get those values which contain 'A' (which would be A,AA,ABC) and use them in a soql query.

Can this be handled within the code? probably getting the picklist values & converting them to string and passing it to the soql query.... something that sort of?

Let me know your suggestions.
Nitin PaliwalNitin Paliwal
Hi Chandra,
Yes in this case , you need to do something like this:
for(Object__c  obj : [select MultiselectPicklist__C from Object__c  ]){
       if(obj.MultiselectPicklist__C != null){
               for(String picklistValues : obj.MultiselectPicklist__C.split(',')){
                    if(picklistValues.contains('your Text')){
                        //do processing here
                    }
               }

       }
}

Let me know if this helps.

Thanks
Nitin
Halvard BastiansenHalvard Bastiansen
I know this is a long time ago, but I found this thread after having the same issue. Here is my solution:

WHERE Multiselect_picklist__c INCLUDES ('%value%', 'value2', 'value3')


Hope that helps :)