Tuesday, 14 March 2017

[#Blogged]Like operator in SOQL

Like operator in SOQL

 Like keyword is same as like in SQL. We can find/get the record utilizing this keyword. Expression is true if the value in the designated fieldname matches characters of text string in the designated value.
The LIKE operator in SOQL and SOSL is homogeneous to the LIKE operator in SQL; it provides a mechanism for matching partial text strings and includes support for wildcards.
* % and _ wildcards are fortified for LIKE operator.
    * % wildcard matches zero or more characters.
    * _ wildcard matches precisely one character.
    * Text string in the designated value must be enclosed in single quotes.
    * LIKE operator is fortified for string fields only.
    * LIKE operator performs a case-callous match, unlike the case-sensitive matching in SQL.
    * LIKE operator in SOQL and SOSL fortifies eluding of special characters % or _.
    * Do not utilize the backslash character in a search except to elude a character.

For example 
List listOfAccounts;
listOfAccounts = [SELECT id, Name
                           FROM Account
                           WHERE Name  LIKE '%test%'];
This query matches both testasish,accounttest, and test.

 SELECT AccountId, FirstName, lastname FROM Contact WHERE lastname LIKE 'AC_%'

Select id, email from contact where email like '%a' or email like '%x';

No comments:

Post a Comment