Comparison operators in Salesforce are very useful to fetch the data in Salesforce Database using SOQL. They are used to compare the data with the values we provide. By using these operators we can customize the data we wanted to fetch from the database. Application of these operators at suitable positions in the queries retrieves the exact data needed. Hence let’s quickly see some of the important Operators in the below table.
Comparison Operators in Salesforce
|=||Equals||Equals operator fetches the data only which is equal to the values provided.||SELECT Name FROM Account WHERE Name = ‘Amazon’|
|!=||Not equals||Not equals operator fetches the data apart from the value provided.||SELECT Name FROM Account WHERE Name != ‘Amazon’|
|<||Less than||Less than operator fetches the data whose fields value is less than the provided value.||SELECT Name FROM Account WHERE NumberOfEmployees < 10|
|<=||Less than or equal||Less than or equal operator fetches the whose field value is less than or equal to the provided value.||SELECT Name FROM Leave__c WHERE NoOfLeaves__c <= 5|
|>||Greater than||Greater than operator fetches the whose field value is Greater than the provided value.||SELECT Name, Phone FROM Student__c WHERE Backlogs > 7|
|>=||Greater than or equal||Greater than or equal operator fetches the whose field value is Greater than or equal to the provided value.||SELECT Name FROM Leave__c WHERE NoOfLeaves__c >= 5|
|LIKE||Like||Like operator fetches the data when the data matches with the value provided.|
Beyond this, we have your wildcard supported in LIKE Keyword. They are “%” and “_”.
% matches zero or more characters.
_ matches exactly one character.
|SELECT Name FROM student__c WHERE Lastname LIKE ‘vi%’|
SELECT Name FROM student__c WHERE Lastname LIKE ‘%vi’
SELECT Name FROM student__c WHERE Lastname LIKE ‘_vi%’
|IN||IN||IN operator fetches the when the data matches the given values.|
We represent the values inside a parenthesis and each value in quotes.
|SELECT Name FROM Contact WHERE State IN (‘Michigan’, ‘Florida’)|
|NOT IN||NOT IN||NOT IN operator fetches the when the data which doesn’t match the given values.||SELECT Name FROM Contact WHERE State NOT IN (‘Michigan’, ‘Florida’)|