Play Games

Search This Blog

Wednesday, April 20, 2016

How to filter records using multiselect picklist field

Assume Subject__c is multiselect picklist field in lead object with available picklist values
Maths
Science
Social
English

Example 1: If you want to query all the lead records in which subject field has Maths,science as selected values(exact match),use "=" in query with all the selected values separated by ";" as below
Query:
List<Lead> leadList =[select id,name from lead where ksk__Subject__c =: ('social;Maths')];
system.debug('Lead Records'+leadList);
Example 2: If you want to query all the lead records in which subject field has any one of Maths or Science as selected value,use includes in the query with each value separated by "," as shown below.
Query:
List<Lead> leadList =[select id,name from lead where ksk__Subject__c includes  ('social','Maths')];
system.debug('Lead Records'+leadList);
Example 3: If you want to query all the lead records in which subject field doesn't have either Maths or science as selected value,then use "!=".
Query:
List<Lead> leadList =[select id,name from lead where ksk__Subject__c !=: ('social;Maths')];
system.debug('Lead Records'+leadList);

No comments:

Post a Comment