Comparison Operators in Salesforce

Introduction

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

OperatorNameDescriptionExample
=EqualsEquals operator fetches the data only which is equal to the values provided.SELECT Name FROM Account WHERE Name = ‘Amazon’
!=Not equalsNot equals operator fetches the data apart from the value provided.SELECT Name FROM Account WHERE Name != ‘Amazon’
<Less thanLess than operator fetches the data whose fields value is less than the provided value.SELECT Name FROM Account WHERE NumberOfEmployees < 10
<=Less than or equalLess 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 thanGreater 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  equalGreater 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
LIKELikeLike 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%’

INININ 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 INNOT INNOT IN operator fetches the when the data which doesn’t match the given values.SELECT Name FROM Contact WHERE State NOT IN (‘Michigan’, ‘Florida’)

 

Reference

https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_comparisonoperators.htm#:~:text=SOQL%20queries%20can%20include%20comparison,use%20in%20a%20SELECT%20statement.&text=String%20comparisons%20using%20the%20equals,insensitive%20for%20all%20other%20fields.

https://www.sfdc99.com/2013/10/12/comparison-operators/

 

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.