Querying Multi-Select Picklists in SOQL

The INCLUDES and EXCLUDES operators are used to filter the multiselect picklist field. The multiselect picklist field in Salesforce allows the user to select more than one value from the list of values provided.

There are use-cases where we want to use a SOQL query and filter by multi-select picklist values. The picklist values can be specified with the AND/OR logic.

We use the Semicolon(;) and Comma(,) characters to add filter values to multi-select picklist fields. A semicolon is used as a special character to specify AND. A comma is used as a special character to specify OR.

Here is the example of filtering the multiselect picklist values. I’ve a custom object “Mobile__c” multiselect picklist field “Brand__c”. The values are in this field are Apple, Samsung, Nokia and HTC.

  • The below query filters on values in the Brand__c field that contains either of these values:
    Apple and Nokia selected.
Select Id, Name From Mobile__c Where Brand__c INCLUDES('Apple;Samsung');
  • The below query filters on values in the Brand__c field that contains either of these values:
    Apple and Samsung selected.
    HTC selected.
Select Id, Name From Mobile__c Where Brand__c INCLUDES('Apple;Samsung','HTC');
  • The below query filters on values in the Brand__c field that contains either of these values:
    Samsung selected.
    Nokia selected.
    HTC selected.
Select Id, Name From Mobile__c Where Brand__c INCLUDES('Samsung', 'Nokia','HTC');