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
Stefaan Somers 12Stefaan Somers 12 

search on multipicklist

Hi,

I have a visualforce page where you can type in a search term.

In Apex code I want to search for this term in my Salesforce-records on all fields, so also in a multipick-list field.

For example, I have a multi-picklist field with the following values :
- Value Test
- Value Other
- Valuet Test2

So when I search on 'Test' I should retrieve the records that have the first or the third value.

How can this be obtained in SOQL or SOSL, making use of a bind expression
ANUTEJANUTEJ (Salesforce Developers) 
Hi Stefaan,

As mentioned in  the below article you could use the query that indicates either one is present:

>> https://help.salesforce.com/articleView?id=000334304&type=1&mode=1

Select id, name from Account where MSP1__c includes('AAA', 'BBB','CCC')

You could use the above query to work on multi select picklist.

I hope this helps and in case if this comes handy can you please choose this as best answer so that it can be useful for others in the future.

Regards,
Anutej
ANUTEJANUTEJ (Salesforce Developers) 
Also, I would suggest you try having a look at the below links as there does not seems to be an option for like operator:

>> https://salesforce.stackexchange.com/questions/180835/query-based-on-multi-select-picklist

>> https://developer.salesforce.com/forums/?id=906F0000000BY0HIAW

As mentioned in the documentation (https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_comparisonoperators.htm?search_text=like)like operator can only be used with string fields, you can raise a new idea or upvote to an existing one in case if you think this feature could be useful for others as well.

 
Stefaan Somers 12Stefaan Somers 12
Hi Anutej,

I know this syntax, but I get the search-term as a variable in the apex-method. So I need to use this term then as a parameter in the SOQL query through a bind variable. I can already get a list of picklistvalues which contains this term, but I cannot use a List<String> as bind parameter in the SOQL query