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
ericmonteericmonte 

Querying multi picklist

hey i have a multipicklist in my code that consists of the following values:

 

MultiSelectField values: "100" , "200", "300", "400" and so forth.

 

So I created a Custom Label and the value consist of "100".

Api Name: Custom_Label

Value: 100

In my code I have the following

List <string> strList = new List <string> ();

add.strList(label.CustomLabel);

 

in my query i have the following:

 

List <object> obj = [select id, multiselect from object where multiselect IN: (strList)];

 

is this the best practice to retrieve record based on multipicklist value? I am trying to limit any hardcoding of values because it may change in the future?

 

Also maybe in the future i want to add an extra value into my list based on the multi-select, for example I want only records with multipicklist containing "100" or "200"?

 

Any thoughts?

SwarnasankhaSwarnasankha

Hi Eric,

 

In order to retrive records based on values entered for a multi-picklist, you need not use hardcoded custom labels. For example

 

  • You want to query records that have a single value selected and the value is 100. Your query should be like:
Select Id, multiSelectVal From SObject Where multiSelectVal = '100;'
or
Select Id, multiSelectVal From SObject Where multiSelectVal = '100'
  • You want to query records that have a more than a single value selected and the values should be 100 and 400. Your query should be like:
Select Id, multiSelectVal From SObject Where multiSelectVal = '100;400'
  • You want to query records that have a more than a single value selected and the values could be single values of say 200 or combination of 300 & 400. Your query should be like:
Select Id, multiSelectVal From SObject Where multiSelectVal INCLUDES ('200', '300;400')

 You can also refer to the following document : http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_soql_querying_multiselect_picklists.htm

 

Hope this helps.

 

 

Bindhyachal Kumar SinghBindhyachal Kumar Singh

Hi ericmonte,

 

Use following Soql query to use multiselect picklist.

 

List <object> obj = [select id, multiselect from object where multiselect includes ('100','200','300','400','100;200','100;300','100;400','200;300','200;400','300;400')];

 I think this will work for 100,200,300,400 picklist value.