You need to sign in to do that
Don't have an account?
Chandra Sekhar CH N V
Like operator substitute for multi select picklist field
I have a query where I am querying a picklist field to gte specific set of values -
I have now changed the data type to multi select and query gets failed.
How to replace the original query so that I can get only s specific set of values from the multi select picklist.
WHERE <picklist field> like '%value%'
I have now changed the data type to multi select and query gets failed.
How to replace the original query so that I can get only s specific set of values from the multi select picklist.
I think that like operator is not supported with multi-select picklist in salesforce. You can just go through the link for the detailed knowledge of which operator to be used with the multi-select picklist.
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_querying_multiselect_picklists.htm
Thanks.
Yes as Ajay said that like is only supported for text fields so you can't directly use like for multiselect. Think about creating formula fields or other fields that is populated by workflow then use like operator.
Thanks!
You can use Includes operator.
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_querying_multiselect_picklists.htm
SELECT Id, MSP1__c from CustObj__c WHERE MSP1__c includes ('AAA;BBB','CCC')
Thanks
Nitin
@ Shailendra - I'm infact using this query in a class so I don't wont to go for an workflow/another formula field again.
@Nitin,, - the query searches for exact match of values if I am not wrong. But my requirement is slight different here. I am actually trying to get specific values from the list of available picklist values which is a multiselect field at the object level. Ex- suppose I have values A,B,C,AA,ABC, then I want to get those values which contain 'A' (which would be A,AA,ABC) and use them in a soql query.
Can this be handled within the code? probably getting the picklist values & converting them to string and passing it to the soql query.... something that sort of?
Let me know your suggestions.
Yes in this case , you need to do something like this:
for(Object__c obj : [select MultiselectPicklist__C from Object__c ]){
if(obj.MultiselectPicklist__C != null){
for(String picklistValues : obj.MultiselectPicklist__C.split(',')){
if(picklistValues.contains('your Text')){
//do processing here
}
}
}
}
Let me know if this helps.
Thanks
Nitin
WHERE Multiselect_picklist__c INCLUDES ('%value%', 'value2', 'value3')
Hope that helps :)