In Salesforce, retrieving the right data efficiently is very important for developers and administrators.
One of the most commonly used features in SOQL (Salesforce Object Query Language) is the LIKE clause, which allows us to search for records based on patterns rather than exact values.
The SOQL (Salesforce Object Query Language) is used to retrieve data from the Salesforce database based on specified conditions and objects.
Whenever you want to fetch Salesforce data in a particular pattern, we can use the LIKE clause to retrieve data.
In this Salesforce tutorial, we will learn about the LIKE Clause in SOQL (Salesforce Object Query Language), including syntax, wildcard characters, real-time examples, performance considerations, and best practices.
What is SOQL?
SOQL (Salesforce Object Query Language) is used to query Salesforce objects. It is similar to SQL but specifically designed for Salesforce data.
With SOQL, you can:
- Retrieve records from Salesforce objects
- Apply filters to records
- Sort data
- Work with related objects and records
What is the LIKE Clause in SOQL?
The LIKE clause in Salesforce Object Query Language (SOQL) is used to perform pattern matching with strings.
It allows you to search for records whose field values match a specified pattern. This is particularly useful for partial matches or for finding records that contain, start with, or end with a specific substring.
The LIKE clause is case-insensitive, which means it treats uppercase and lowercase characters as equivalent. It can only be used with fields of type String, Text, or Picklist, allowing us to match names, email addresses, or custom text fields.
Instead of searching for exact values, it allows you to:
- Find records starting with a value
- Find records ending with a value
- Find records containing a value
It is mainly used with:
- Text fields
- String fields
- Picklist fields
It is case-insensitive, meaning uppercase and lowercase are treated the same
Syntax: Declaring the LIKE Clause in SOQL
SELECT fields FROM Object_Name WHERE field LIKE 'pattern'In the SELECT clause, we specify the fields we want to retrieve values from. In the FROM clause, specify the object name (standard or custom object).
In the WHERE clause, we add a condition on fields, and using the LIKE clause, we can specify the string pattern we want to match with records in the object. It can include wildcard characters to define the pattern.
Wildcard Characters in LIKE Clause SOQL Query
The wildcard characters are used with the LIKE clause to perform pattern matching on string fields. It allows us to retrieve records that match specific patterns rather than exact values.
1. % (Percentage Sign)
This sign declares a pattern, ensuring that whenever we retrieve records, those records meet it.
For example, when we add a % sign after any character or string, ‘A%’. After executing the query, you will see only those records that start with A.
Example: Use % (Percentage Sign) in SOQL Query
For example, we have multiple records in the opportunity object, and we want to display only those opportunities that share a unified name.
Here, we need to use the % wildcard to retrieve all records that contain the word “United” in the opportunity name.
SELECT Name FROM Opportunity WHERE Name LIKE 'United%'In the above SOQL query, we first specified the fields we wanted to display in the results, then provided the object name from which we retrieved the records.
Using the WHERE clause, we added a condition, and using the LIKE clause, we retrieved only the names of opportunities that start with the word “United”.
After executing the query, you can see the results of only those opportunities whose names start with the word “United”.

In this way, we can use the % wildcard character to get the result in a particular pattern that we defined in SOQL using the LIKE clause.
2. _ (Underscore)
This sign is used when we want to retrieve records that match exactly a single character. For example, when we add _ underscore sign after any character, ‘A_’.
After executing the query, you will see only those records displayed that have only two-character strings in particular fields, such as At, Ap, Ax, etc.
Example: Use _ (Underscore) in SOQL Query
For example, we have multiple records in the contact object and want to display only male records. Here, we need to use the _ wildcard character to retrieve all male contact records from the contact object.
To identify male contacts’ records, we have a salutation field in the contact object with two values: Mr. and Ms. Here, Mr. represents male contacts, and using the underscore (_) wildcard character, we can fetch those records.
SELECT Salutation, FirstName, LastName FROM Contact WHERE Salutation LIKE '_r.'In the above SOQL query, we added a salutation field to retrieve male contacts who use ‘Mr.’ as their salutation.
After that, using the LIKE clause and the _ wildcard character, we added _r. This pattern retrieved contact records that have 2 characters and end with ‘r’, which is Mr.

Common LIKE Patterns in SOQL
| Pattern | Meaning |
|---|---|
| ‘A%’ | Starts with A |
| ‘%A’ | Ends with A |
| ‘%A%’ | Contains A |
| ‘_A%’ | Second letter is A |
Real-Time Use Cases of the LIKE Clause in SOQL Queries
In the examples below, we will see how the LIKE clause can be used to retrieve records whose field values match a specified pattern.
Example: Find Records Starting With “XYZ”
When we add the % wildcard character at the end of the string that we provided, the result will display the result that starts from the provided string.
In the SOQL query below, we first added the opportunity fields we want to display in the results. After that, we added a condition using the WHERE clause.
Then, using the LIKE clause, the opportunity records whose names start with the ‘grand’ string will be displayed.
SELECT Id, Name FROM Opportunity WHERE Name LIKE 'Grand%'
In this way, we can use the LIKE clause in SOQL to retrieve results that start with a particular string in the Salesforce object.
Example 2: Filtering Records Based on Partial Data
In a SOQL query, whenever we find a string anywhere or in the middle of a field, we must use two % signs, and between them, we need to add a string from which we want to retrieve records.
SELECT Id, Name FROM Opportunity WHERE Name LIKE '%tall%'In the above SOQL query, we added a LIKE clause to find the ‘tall’ string anywhere in the name field in the opportunity object. For that, when we want to find the middle string, we need to add the % sign to the beginning and end of the string.
As a result, you can see that we entered ‘tall’ as a string to filter relative records by it, and we retrieved records that contain the word ‘tall’ somewhere in the name field.

Let’s see another example: this time, we will retrieve records for the particular word that is anywhere in the name field.
For example, we want to retrieve account records that have the ‘oil’ words anywhere in the name field.
SELECT Id, Name FROM Account WHERE Name LIKE '%oil%'
Example: Use a Different Clause in the LIKE Clause in SOQL
When we want to add multiple conditions to the LIKE clause, we can use additional clauses to query the results. In the other clause, we can combine LIKE with other filters and logical operators, such as AND and OR.
For example, we want to retrieve opportunity records whose names contain the “Edge” character and whose stages are nearing completion.
In the SOQL query below, we retrieved fields from the Opportunity object where the opportunity name starts with ‘Edge,’ and the stage is ‘Closed Won’.
For that, we used the LIKE clause to retrieve records starting from a particular character, and then added another condition using the AND operator, which resulted in closed won opportunities.
SELECT Id, Name, StageName FROM Opportunity WHERE Name LIKE 'Edge%' AND StageName = 'Closed Won'
Example: Find Records With Specific Patterns Using SOQL
For example, when we want to retrieve account records whose account name starts with ‘U’, the second character can be any single character, and the third character is ‘I’. We can then use the LIKE clause and wildcard character in SOQL queries.
SELECT Id, Name FROM Account WHERE Name LIKE 'U_i%'In the above SOQL query, we used the LIKE clause to retrieve records according to the provided pattern, so here, we want to get account records whose names started with U, and after that, we used _ so that the second alphabet can be any single character and then we have I in that string so we want to find records in this pattern.

Frequently Asked Questions
Q1: Is LIKE case-sensitive in SOQL?
No, it is case-insensitive
Q2: Can we use LIKE with numbers?
No, only string fields
Q3: Can LIKE be used with IN?
No, not directly
Q4: Which is better: LIKE or SOSL?
Use:
LIKE → for simple filters
SOSL → for search functionality
Conclusion
I hope you have got an idea about the LIKE Clause in SOQL (Salesforce Object Query Language).
The LIKE clause in SOQL is a powerful feature that enables developers to retrieve records based on patterns rather than exact values. It is widely used for search functionality, data filtering, and user-driven queries.
However, it should be used with care, especially in large datasets, as it can affect performance. Understanding wildcard characters, their limitations, and best practices will help you write efficient, optimized SOQL queries.
You may like to read:
- HAVING Clause in SOQL
- Salesforce Field Security in SOQL WITH Security Enforced
- GROUP BY Date Clause in SOQL
- GROUP BY Clause in SOQL
- ORDER BY Clause in SOQL
I am Bijay Kumar, the founder of SalesforceFAQs.com. Having over 10 years of experience working in salesforce technologies for clients across the world (Canada, Australia, United States, United Kingdom, New Zealand, etc.). I am a certified salesforce administrator and expert with experience in developing salesforce applications and projects. My goal is to make it easy for people to learn and use salesforce technologies by providing simple and easy-to-understand solutions. Check out the complete profile on About us.