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:

SOQL NOT LIKE operator to exclude records ending with specific characters
The way we excluded the records with specific characters using the NOT LIKE operator in the previous example, we can also remove records that end with specific characters.
For example, I have executed an SOQL query that will exclude the account records with the character ‘s‘ in the end.
SELECT Id, Name
FROM Account
WHERE NOT Name LIKE '%s'Output:

In the output, the query returned the account names and excluded the names ending with ‘s.’
SOQL NOT LIKE Operator to Exclude Specific Substring Matches
A specific substring can be a value like “2025-Q1“. For example, we have this value in the opportunity names, so we use the syntax below to remove the records with this value.
SELECT Id, Name
FROM Opportunity
WHERE NOT NAME LIKE '%2023-Q1%'This query filters out opportunities containing “2025-Q1” anywhere in their name.
Add Multiple Filters with NOT LIKE in SOQL
When you have to query multiple other operators and values using NOT LIKE, then you can follow the query below.
For example, we need to query the account records, excluding those with the industry as “technology” and those with the text “chemicals” anywhere in the name. For this, we can use the query below.
SELECT Id, Name, Industry FROM Account WHERE NOT (Industry LIKE '%Technology%' AND Name LIKE '%Chemicals%')
This way, we can add multiple filters to the NOT LIKE operator in Salesforce SOQL.
Conclusion
In Salesforce SOQL, the NOT LIKE operator is useful for filtering out records that match specific patterns and excluding them from query results.
In this Salesforce SOQL tutorial, we have learned about the NOT LIKE operator and also its execution in different scenarios.
Following the above syntax, you can efficiently execute the NOT LIKE operator in your SOQL queries to exclude specific records.
You may also like to read:
- Dynamic Queries in SOQL
- Polymorphic Relationships in Salesforce SOQL
- Create a For Loop to Iterate Through a SOQL Query
- How to Find Deleted Records in Salesforce using SOQL
- SOQL Governor Limits in Salesforce

Abhijeet is a skilled Salesforce developer with experience in developing and integrating dashboards, data reports, and Salesforce applications. He is also skilled at optimizing processes and flow automation processes, coding, and executing complex project architecture. Read more about us | LinkedIn Profile.