You need to sign in to do that
Don't have an account?
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;
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
A multi-select picklist should be a semi-colon separated string in Apex, therefore something like:
String[] regions = bsc.Region__c.split(';');
should work.
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(';');
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
Worked perfectly (all of your replies). Thank you, so much -- and so fast. SFDC Dev Community totally rocks!