Like Operator usage in Apex

In SOQL, the LIKE operator is supported for string fields only. So, we cannot use it against any other field data types.

Example:


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

(or)


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

where searchKeyword is an Apex variable.

Leave a Reply