SOQL Includes, Excludes Operators: In our previous salesforce Tutorial we have learned about SOQL ORDER BY clause. In this salesforce training tutorial we are going to learn about SOQL INCLUDES, EXCLUDES Operators in salesforce.
SOQL Includes and excludes operators are mainly used to filter multipicklist field values in salesforce. These operators are used for only multipicklist values. Multipicklist values are those whose have more than one picklist values .
For example a student must have many skills to get a job (salesforce, Java, C, C#, ORACLE etc).
- SELECT name, country__c, Student_skills__c FROM Student__C .
From above SOQL statement all the records from Student object has retrieved.
Includes operator is used to filter and retrieve the data that contains any of the specified values in SOQL statement.
- SELECT name, country__c, Student_skills__c FROM Student__C WHERE student_skills__C INCLUDES (‘salesforce’).
From above SOQL INCLUDES operator statement we filtering the data whose student skills is equal to ‘salesforce’.
- SELECT name, Country__C, Student_skills FROM Student__c WHERE student_skills EXCLUDES (‘salesforce’)
From above SOQL statement we fetching the data whose student will have no salesforce skills. condition must be written in single quotations and braces as shown above.