Like operator in Salesforce SOQL

Like operator in Salesforce SOQL

In SOQL, the LIKE operator is supported for string fields only. So, we cannot use it against any other field data types.
 
Syntax:
String strSOQL = ‘SELECT FieldAPIName FROM sObject WHERE FieldAPIName LIKE ‘%’ + searchKeyword + ‘%”;

Example:


String strSOQL = ‘Select Name From Account WHERE Name LIKE ‘%’ + searchKeyword + ‘%”;

where searchKeyword is an Apex variable.


(or)


List < Contact > listCon = [ SELECT Id, FirstName FROM Contact WHERE FirstName LIKE ‘%test%’ ];
System.debug( ‘List contacts are ‘ + listCon );

Leave a Reply