You need to sign in to do that
Don't have an account?
MarkLevy
SOQL Query : LIKE / Substring in Multi-select picklist
Is it possible to query using SOQL for a substring on a multi-select picklist? LIKE seems to not work on multi-select picklists.
Example:
MultiSelectPicklist = 'myfavoritefruitisapple;myfavoritecolorisgreen;ihatered'
I'd want to query using WHERE and search for the substring 'favorite' such that it will pick up anything with 'myfavoritefruitisapple' or 'myfavoritecolorisgreen' but not pick up the 'ihatered' people.
Is something like this possible?
Thanks!
Example:
MultiSelectPicklist = 'myfavoritefruitisapple;myfavoritecolorisgreen;ihatered'
I'd want to query using WHERE and search for the substring 'favorite' such that it will pick up anything with 'myfavoritefruitisapple' or 'myfavoritecolorisgreen' but not pick up the 'ihatered' people.
Is something like this possible?
Thanks!
Here is how I solved it at my end. I created a text field on the Object called TestColorText__c. I then write the following trigger, where TestColor__c is my multiselectPickList
I was then able to use the LIKE operator in SOQL queries. Note that you wil have to update existing records to populate the TestColorText__c for this to work
Harris Mir
All Answers
Multi Picklists are pretty limited in SOQL queries. Refer https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_querying_multiselect_picklists.htm for more details.
However, your requirement is absolutely possible in an APEX class.
You can fetch the data from your object using a Generic SOQL query and filter it further for the Multi Picklist field.
INCLUDES works only if you provide the complete value of one of the entries in the optionset.
It doesn't take partial text, as Mark asked in his question.
Here is how I solved it at my end. I created a text field on the Object called TestColorText__c. I then write the following trigger, where TestColor__c is my multiselectPickList
I was then able to use the LIKE operator in SOQL queries. Note that you wil have to update existing records to populate the TestColorText__c for this to work
Harris Mir
Just to improve your idea a little more. If I were you, I would have tried a formula field instead of a text field.
This would have saved a trigger for me. Just a thought.
The problem with the above approach is that you will have to remember to update the formula if tomorrow you provide a new option. But it does save you a trigger
Mark, if Harris's trigger solves your problem, please mark it as best answer!