In Salesforce, we can query information related to the List View using the ListView object, which provides queries for the public list view of the sObjects.
By using the ListView object in SOQL queries, we can only query public list views or list views accessed by the user executing the query on the sObjects, meaning private list views cannot be queried in SOQL.
In this Salesforce tutorial, I will explain how to query the ListView of an object in Salesforce SOQL.
Query the ListView of an Object in Salesforce SOQL
To query the list view of a Salesforce object in SOQL, we will use the standard object ListView.
For example, we have to query the list views of the Account object, and then we can execute the SOQL query below.
SELECT Id, Name, DeveloperName, SobjectType
FROM ListView
WHERE SobjectType = 'Account'Output:

This way, we can execute the SOQL query to fetch the list view of a specific object in Salesforce.
Let’s take another example, where we will query the username of the user who created those list views for that specific object.
In the SOQL query below, we will query the list view of the Account object, along with the names of users who created those list views.
SELECT Name, CreatedBy.Name
FROM ListView
WHERE SobjectType = 'Account'Output:

This way, we can query the Salesforce List views in SOQL queries using the ListView objects.
Export List Views with Shared to Details Using SOQL in Salesforce
In this example, we will export the object records from a specific list view into an Excel or CSV file, similar to exporting opportunity records that appear when you set the list view to ‘Closing this month’.
We will execute the SOQL query in the Salesforce Workbench to retrieve the desired record with the filter conditions specified in the list view. Now, open the Salesforce Workbench and follow the steps below.
- First, we need the ID of the list view for which you want to export records. To get the list view ID, navigate to the list view and copy the 15-digit code or list view API name from the URL.
- In my case, it showed the API name of the list view.

- After this, log in to your Salesforce Workbench account and ensure that you select “Production” in the Environment option.
- In the Utilities tab, select the REST Explorer option.

- In the REST Explorer, select the Get option and execute the URL below.
/services/data/v62.0/sobjects/Opportunity/listviews/ClosingThisMonth/describeReplace the Opportunity with the object API name and ClosingThisMonth with the list view API name or the ID we got from the list view URL.

- As we execute the URL, it will generate the SOQL query in the response body Order by section.
- Copy the generated SOQL query to the clipboard.

- Navigate to the queries tab, select the SOQL query, and paste the copied query into the query editor. For the test run, select ‘View as List’.
- When the query generates the desired records, select ‘View as Bulk CSV‘ and then execute the query again.
- When the bulk API job is finished, it returns the batch result. From there, we must click on the document icon to download the records stored in a CSV file.

This way, we can download the list view records into a CSV file using the SOQL in the Salesforce workbench.
Errors in executing the SOQL query to get the list view:
The most common error you can face while executing the SOQL query is getting the parent relationship query error.

If the records you are querying have a parent object, then you must change the workbench settings.
In the settings, navigate to the Query and Search options section and select the checkbox That Allows SOQL Parent Relationship Queries.

By applying this setting, we can resolve the parent relationship query error in the Salesforce workbench.
Conclusion
In Salesforce, we can efficiently query the object’s list view by following the above methods, where we have learned to query the information related to the object list view for different scenarios.
Additionally, we have utilized the Salesforce Workbench to query and export the list view records of a specific Salesforce object. Additionally, I have explained the solution to resolve the parent relationship query error that occurs when executing the SOQL query in the Workbench.
You may also like to read:
- Query Multi-Currency Fields in Salesforce SOQL
- Query Activity Related To Fields With SOQL in Salesforce
- Return Map Result from SOQL Query in Salesforce Apex
- Use Bind Variables in Salesforce SOQL
- SOQL Governor Limits in Salesforce
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.