Hello Everyone, In this tutorial, I am going illustrate LIKE Operator with Example in Salesforce SOQL query. In this unit, you will see how we can use LIKE Operator in SOQL and Dynamic SOQL query and also take a look at some properties of this operator.

After completing this tutorial, you’ll able to:
  • Know properties of LIKE Operator
  • Use LIKE Operator in SOQL query.
So let's start,

LIKE Operator

Some properties of LIKE Operator are.
  1. LIKE operator performs a case-insensitive match.
  2. It supported only string fields.
  3. In SOQL and SOSL it supports escaping of special characters % or _.
  4. In  LIKE operator string in the specified value must be enclosed in single quotes.
Use LIKE Operator in SOQL query.

Scenario 1: Select all Account records with Name starts with 'AW'.
 List<Account> lstAcc=[SELECT Name, Industry FROM Account WHERE Name Like 'AW%'];
 In Dynamic SOQL
 List<Account> lstAcc=DataBase.query('SELECT Name, Industry FROM Account WHERE Name Like \'AW%\'');

Scenario 2: Select all Account records with Name Ends with 'AW'.
 List<Account> lstAcc=[SELECT Name, Industry FROM Account WHERE Name Like '%AW'];
In Dynamic SOQL
 List<Account> lstAcc=DataBase.query('SELECT Name, Industry FROM Account WHERE Name Like \'%AW\'');

Scenario 3: Select all Account records with 'AW'  in between Name.
 List<Account> lstAcc=[SELECT Name, Industry FROM Account WHERE Name Like '%AW%'];
In Dynamic SOQL
 List<Account> lstAcc=DataBase.query('SELECT Name, Industry FROM Account WHERE Name Like \'%AW%\'');

See also:
Conclusion:
Hope you like this tutorial, for any query or suggestions please feel free to comment.
Thank you.