Salesforce Like Operator in SOQL Query
Biswajeet
March 24, 2014 No Comments on Salesforce Like Operator in SOQL Query
Like Operator in SOQL act as a Comparison operator for String Field Expression. Expression is true if the value in the specified fieldName matches the characters of the text string in the specified value. The LIKE operator in SOQL and SOSL is similar to the LIKE operator in SQL; it provides a mechanism for matching partial text strings and includes support for wildcards.
Use Cases Of LIKE Operator:
- The LIKE operator is supported for string fields only.
- The % and _ wildcards are supported for the LIKE operator.
- The % wildcard matches zero or more characters.
- The _ wildcard matches exactly one character.
- The text string in the specified value must be enclosed in single quotes.
- The LIKE operator is supported for string fields only.
- The LIKE operator performs a case-insensitive match, unlike the case-sensitive matching in SQL.
- The LIKE operator in SOQL and SOSL supports escaping of special characters % or _.
- Don’t use the backslash character in a search except to escape a special character.
Example1:
The following query matches Appleton, Apple, and Appl, but not Bappl:
SELECT Id, Name FROM Account WHERE Name LIKE 'appl%'
Example2:
The following query matches Appleton, Apple, and Bappl, but not Appl:
SELECT Id, Name FROM Account WHERE Name LIKE 'appl_%'