SOQL Not Like is not supported by Salesforce, requiring alternative methods to exclude specific patterns from query results. Salesforce does in fact supports the LIKE
operator, which allows pattern matching using the %
wildcard (representing zero or more characters) and _
(representing a single character). For example:
SELECT Name FROM Account WHERE Name LIKE 'Acme%'
This query retrieves all accounts whose name starts with “Acme.”
Typically when writing SQL you can use NOT as a condition in front of LIKE.
Workarounds for SOQL NOT LIKE in Salesforce
Since NOT LIKE
is not directly supported in SOQL, you can achieve similar functionality using the NOT
operator in combination with LIKE
.
1. Using NOT and LIKE Together
You can exclude records that match a certain pattern by writing:
SELECT Name FROM Account WHERE NOT Name LIKE 'Acme%'
This retrieves all accounts except those whose names start with “Acme.”
Best Practices for Using SOQL NOT LIKE
- Optimize for Performance: Using multiple
NOT LIKE
conditions can impact query performance, so try to limit unnecessary exclusions. - Consider Alternative Filters: If possible, use indexed fields and avoid complex wildcards that slow down queries.
We recommend using Workbench to test your SOQL skills
Enjoy this article?
Check out our Master SOQL for Salesforce blog