In Salesforce, SOQL supports various operators for applying filters and conditions to query data, and one such operator is NOT LIKE. This operator is helpful in SOQL queries when you need to exclude records that match a specific pattern.
In this Salesforce tutorial, I will explain how to use the NOT LIKE operator in Salesforce, and with the help of examples, we will discuss the use case of the NOT LIKE operator in SOQL queries.
NOT LIKE Operator in Salesforce SOQL
In Salesforce SOQL, the NOT LIKE operator filters records that do not match a specified pattern. It works with text fields and uses wildcard characters such as ‘%’ and ‘_’ to define patterns.
Where ‘%’ is used to match zero or more characters, and underscore ‘_’ is used to match a single character.
The syntax for using the NOT LIKE operator in SOQL :
SELECT fields
FROM ObjectName
WHERE NOT FieldName LIKE 'text value'
Now, we will see the following scenarios for using the NOT LIKE operator in Salesforce SOQL queries.
Query to Exclude Records Containing Specific Text
For example, you have to query account records and want to exclude the documents where the name does not contain ‘Chemicals,’ so we can use the NOT LIKE operator to exclude those records.
SOQL query using NOT LIKE:
SELECT Id, Name
FROM Account
WHERE NOT NAME LIKE '%Chemicals%'
The above SOQL query will return the account name records, excluding the one with the text value “Chemicals.“
Output:

This way, we can use the NOT LIKE operator in the Salesforce SOQL query to exclude records containing specific text values.
SOQL NOT LIKE Operator to Exclude Records Starting with Specific Characters
Now, instead of using a text, when you need to exclude text with specific characters, such as accounts whose names begin with “Uni,” we can use the NOT LIKE operator.
SOQL query with NOT LIKE operator:
SELECT Id, Name
FROM Account
WHERE NOT Name LIKE 'UNI%'
Output:
