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
JP Seabury @ ComcastJP Seabury @ Comcast 

How Do I Convert the Values of a Multiselect Picklist Into a String?

USE CASE: I've queried a record from an object that contains a multiselect picklist field (Region__c):


Employee__c bsc = [SELECT id, Division__c, Region__c , User__c FROM Employee__c
WHERE User__c = :UserInfo.getUserId()];


Now, I want to pull all of the selected values of that Multiselect picklist field into a String[], so I can use that in another query.

The following query doens't work because bsc.Region__c is not a string -- but how can I query to see if Order__c.State__c is a member of bsc.Region__c?

oldestOrder = [SELECT id FROM Order__c
WHERE OwnerId = :q.QueueId AND
Status__c NOT IN :ignoreStatus AND
State__c IN :bsc.Region__c
ORDER BY First_Submit_Date__c

LIMIT 500][0].id;

Best Answer chosen by Admin (Salesforce Developers) 
garybgaryb

A multi-select picklist should be a semi-colon separated string in Apex, therefore something like:

 

String[] regions = bsc.Region__c.split(';');

 

should work.

All Answers

garybgaryb

A multi-select picklist should be a semi-colon separated string in Apex, therefore something like:

 

String[] regions = bsc.Region__c.split(';');

 

should work.

This was selected as the best answer
SuperfellSuperfell

MSPs have includes & excludes functions for SOQL, but i think you're going the other way around, State__c isn't an MSP, right? in which case Region__c is a string with ; delimitors, so you can covert it to a string [] with 

String [] mspValues = bsc.Region__c.split(';');

VPrakashVPrakash

As Multi-select picklist fields contain a list of one or more items from which a user can choose multiple items. One of the items can be configured as the default item. Selections are maintained as a string containing a series of attributes delimited by semicolons. For example, a query might return the values of a multivalue picklist as “first value; second value; third value”.

 

you have to split the field and add this to a new string, this string can be usedin your query. 

 

Like,

string str = Region__c;

string[] str1 = str.split(';');

 

use str1 in your query.

 

Hope this helps

 

 

 

 

JP Seabury @ ComcastJP Seabury @ Comcast

Worked perfectly (all of your replies).  Thank you, so much -- and so fast.  SFDC Dev Community totally rocks!