While working on Salesforce records, I need to filter records by matching fields against multiple specified values. To retrieve those records, we use an IN operator/clause in SOQL to fetch the matching field records in Salesforce.
In this Salesforce tutorial, we will learn about the IN operator/clause in SOQL(Salesforce Object Query Language). In that, I will explain the functionality of the IN clause and how to use it in SOQL queries with different examples.
Explain the IN Operator/Clause in SOQL
When we have a number of records in Salesforce, using the IN clause in SOQL, we can filter the records by matching fields against multiple specified values.
It works similarly to the IN operator in SQL and allows querying for records where a field’s value matches any value from a given list.
The IN clause allows us to query multiple values at once instead of using multiple OR conditions in a SOQL query. Then, we can also pass a collection(List or Set) into the IN clause, making queries dynamic.
Syntax: Declaring IN Operator/Clause in SOQL
SELECT fields FROM Object_Name WHERE Field_Name IN (Value1, Value2, Value3)
- SELECT: The SELECT clause specifies the fields to retrieve in the query results.
- FROM: The FROM clause defines the Sobject from which to retrieve data.
- WHERE: The WHERE clause filters the query results based on specific conditions, as you specify.
- IN: Using the IN operator/clause, we can find all records that contain provided values in a particular field.
Example:
Let’s understand the IN operator using a basic example. We want to retrieve records so that in the query result, we will get only those records in which industry is ‘Banking,’ ‘Technology,’ or ‘Healthcare.’
SELECT Id, Name, Industry FROM Account WHERE Industry IN ('Banking', 'Technology', 'Healthcare')
In the above SOQL query, we provided fields that we want to display in the result and the object from which we want to retrieve records.
After that, in the WHERE clause, we provided a condition that we only want those records whose industry field contains the provided values with the IN clause.
Using the IN operator/clause, we don’t need to add different conditions for each value or add the OR operator. Here, we only need to provide the values for which we want to retrieve records.
In the image below, you can see the records where only those records get retrieved whose industry is ‘Banking,’ ‘Technology,’ or ‘Healthcare.’

Example: Use an IN Clause With IDs in SOQL
Now, we will understand how to use the IN operator/clause to retrieve records when passing multiple IDs.
For example, we want to retrieve opportunity records that are related to the account ID that we will provide to the IN clause. So that we only get those records in which the account ID is XYZ (provide as per your requirement).
SELECT Id, Name, Account.Name FROM Opportunity WHERE AccountId IN ('0015i00000KafC9AAJ', '0015i00000KafCCAAZ')
In the above SOQL query, we added the opportunity name and account name, and we want to retrieve records from the opportunity object. But