+ Start a Discussion
J BengelJ Bengel 

SOQL: Selecting for records that have more than one value selected in a multi picklist field

This may not even be possible, since SOQL for this type of field is pretty skeletal, and the type itself can't really decide what kind of data it wants to be.
All I want my query to tell me is if more than one selection has been made for the field. I'm not concenred with what selections were made, just that there's more than one. LIKE is a bust, and I thought maybe Includes(';') might be a workaround, but that gets interpreted as me looking for NO values selected (I guess it's seeing the pattern as null AND null?).
The problem is mainly that the type is caught between string and an array of strings, and isn't really either of these. If it was actually a string then LIKE '%;%' would give me my answer. If it was actually an array, then one would assume that SOQL would allow for the use of .size() to identify when more than one selection exists. But in that limbo state where you're not really either species, there isn't really a good solution. Once I've gotten it into Apex, I should be able to split it and create a List<String> from it, and then test for the size() of that. But I was hoping to be able to query for this without having to do it in code.
AbhishekAbhishek (Salesforce Developers) 
There are use-cases where you want to use a SOQL query and filter by multi-select picklist values. The picklist values can be specified with the AND/OR logic. Use the Semicolon and Comma characters to add filter values to multi-select picklist fields.


For further reference you can check the below,
https://salesforce.stackexchange.com/questions/301850/soql-query-for-multiselect-picklist


It might help you.
J BengelJ Bengel
Includes/Excludes only lets you specify that the values you're looking for exist in the set of values selected. That's not what I'm trying to query for. I just want to know if there were multiple selectoins made, without considering what they may have been. The specific use case I'm working on delas with a custom field in the EDA managed package on Contact that captures Race -- or Races. It's a multi-select picklist that came with the selections:
American Indian or Alaska Native
Asian
Black or African American
Hispanic or Latino
Native Hawaiian or Other Pacific Islander
White 

The agency we're reporting to wants a single value, but allows for "Other/Multiple" as one of their options. We added "Other/Multiple" and "Not Provided" to the list to allow for this, but that opens up the possibility that rather than use the "Other/Multiple" choice, they'll use the field as it was designed and select more than one choice from the "stock" list. If they do that, (say they choose "White" and "Hispanic or Latino") I need to intepret this as "Other/Multiple", while also accounting for the possiblity that I'll encounter "Other/Multiple" in the data as well. So what I was hoping for was to be able to select for WHERE hed__Race__c = "Other/Multiple" or hed__Race__c  [more than one choice selected] 
I tried 
hed__Race__c Like '%;%'
which gave me a type mismatch and 
hed__Race__c Includes ';'
which just treated the expression as if I'd asked for a null value (null AND null, I suppose) because it returned all of the records that had no value in the field.

I suppose I could create an IN list that included every possible permutation but that's a LOT of combinations to test for. Especially considering that you could theoretically have up to 6 different chioces (technically you could have up to 8, but that would be stupid). 

So it appears that my only alternative is to select all of the applicable records into a list and test each one in a for loop to see if there's more than one value present.. Something like:
String raceCodes = hed___Race__c;
if(raceCodes.contains(';')) // 
    raceCodes = 'Other/Multiple';
I was hoping to avoid having to process every record this way in a loop, but that appears to be my only option at this point. I think this is the only multi-select field we have to worry about in this dataset, so maybe it's not that big a deal (for this use case), but I can see other cases where I woudln't be bringing the query results into an Apex class and this capablity would be extremely useful.