The LIKE operator in SOQL and SOSL is quite similar to the LIKE operator in SQL; it provides a mechanism for matching partial text strings and includes support for wildcards.
Suppose we need to delete some test records of Account object, all test records are created having account name is test. Account name may "testasish" or "accounttest", how can we get those record by Soql query ?
For this propose LIKE operator is useful.
For example
List<Account> listOfAccounts;
listOfAccounts = [SELECT id, Name
FROM Account
WHERE Name LIKE '%test%'];
This query matches both testasish,accounttest, and test.
Use Cases Of LIKE Operator
Suppose we need to delete some test records of Account object, all test records are created having account name is test. Account name may "testasish" or "accounttest", how can we get those record by Soql query ?
For this propose LIKE operator is useful.
For example
List<Account> listOfAccounts;
listOfAccounts = [SELECT id, Name
FROM Account
WHERE Name LIKE '%test%'];
This query matches both testasish,accounttest, and test.
Use Cases Of LIKE Operator
- 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 _.
- Do not use the backslash character in a search except to escape a special character.
4 comments:
how to use like operator in SOSL query?
How to use LIKE operator in SOSL query
Hi Pramodh T
Sorry for late reply, Here is link to answer your question.
http://salesforceworld4u.blogspot.in/2015/10/how-to-use-like-operator-in-sosl.html
Like operator in sosl
Post a Comment