Skip to main content

Export records from List view – ListView API

As part of the Winter’15 release salesforce introduced the List View API features which helps us to get details and records of list views for an object. I was started exploring more about the List view API and trying to build an use case using that. So I searched about List View in the IdeaExchange site then found that many users are looking for a solution to export records to excel directly from the list view.

I built a solution for that Idea, which helps user to download all the records directly from the List view for both standard and custom object. You don’t have to make any change in the code to use this functionality for different objects. All you need is to create a custom button for that object as mentioned below. Lets take an example for Account object

1. Go to Setup –> Accounts –> Buttons, Links and Actions
2. Click ‘New Button or Link'
3. Enter  Label, Name and select display type as ‘List Button’


4. Content source as “Onclick Javascript” and paste the below code

Then include the button in the List view page of the object. Now open any list view of the account object and click the ‘Export to Excel’ button. It will export all records of that list view. Repeat the above steps for creating button for other objects.


ListView API in Winter15:

Lets see the logic behind the scene, firstly lets take a look into the ListView API. Currently ListView API is available in both SOAP and REST format. Following are the functionalities you can call using REST service. Documentation link

List Views - Get the List of List views for a particular object. Run the following in the workbench to get the result.
Describe - It will provide the  definition of particular list view, including SOQL.
URL - /services/data/v32.0/sobjects/Account/listviews/{ListId}/describe
{ListId} – Enter the ID of the List view
Results – It will return the records of the particular list view including column details.
URL - /services/data/v32.0/sobjects/Account/listviews/{ListId}/results
{ListId} – Enter the ID of the List view
To know more about the List view API functionality check the "Super ListView viewer" by Andrew Fawcett

Next moving on the code the apex class will call the list view API describe function using HTTP callouts. Then using the JSON parser, parse the JSON string output to get details like SOQL and Columns information. Once we get the SOQL query of the list view then its not a big deal to display the records in a visualforce page. The table in the visualforce page will display the columns dynamically based on the columns in the list view.

The reason why I’m not using the results listview API functionality  in my code is, the size is default to 25. So we can’t get more than 25 records from the list view using REST API. 
Remote Site Setting:
Since we are making HTTP callouts in apex class, we have to setup remote site to call salesforce by itself.  Follow the below steps

1. Go to Setup->Remote Site –> New
2. Add the Name and in the URL enter the domain name of your org
3. Then click save

So now we can able to export records directly from the list view. I have tested this functionality with around 20K records. You can also check  my previous article here to exporting more records without hitting view state limit or collection size limits. The complete source code is available here.

You can also deploy to your org by clicking the below button
Deploy to Salesforce

Update : For any issues or bug or enhancement, please log it in Github repository. It will be more helpful for me to quickly respond to your queries -


  1. Very helpful article, Thank you for posting.

    I have a question, Is there any possible way to update List View describe result using httpreq or metadata api.

  2. This comment has been removed by the author.

  3. This is such an informative post. Online converters are also pretty good at it's job. I would like to share one I've found here

  4. Thank you for excellent article.Great information for new guy like antimalware service executable

  5. I'm positive you might be like me, you may have additionally noticed many images displayed which have been taken by a mess of photographers, all with numerous imagery of what they prefer to take photos of. All hoping it's going to attraction to you so you'll take it house and place their creation in your wall to exhibit to others. If you want to learn more about this topic, then please visit here

  6. Earlier than discussing the differing kinds of applications in addition to what they provide and to whom, it might be finest to begin with a primer on picture graphics and format. If you want to learn more about this topic please visit

  7. Never too late to start learning at Salesforce Training in Australia even though you don't have any programming knowledge you can excell in Salesforce Training in London United Kingdom (UK) because it is all about your customers, so this time find the best Salesforce Training in Europe. This way we will learn Salesforce CRM.

  8. Thanks a lot for sharing a great blog I was just browsing through the internet looking for some information and came across your blog. I am impressed by the information that you have on this blog. It shows how well you understand this subject. Bookmarked this page, will come back for more keep going on it helped me a lot I have gained a lot of knowledge by reading your blog.

    Oracle Apex Training
    apex oracle training
    oracle apex training online
    oracle apex courses online
    Oracle APEX 19.1 Training
    oracle apex 18 training
    oracle apex 5 training


Post a Comment

Popular posts from this blog

Avoid Duplicate Records Using Flow

In this blog post lets see how to avoid duplicate records in Salesforce using the powerful feature – Flow , As the word says, flow easily flows to fulfill the requirements with ease. ☺  Many think of appexchange solutions and source code to avoid the duplicate record in salesforce, But the method I'm going to explain here is completely different and very simple. It helps you to reduce your code and can easily rebuild for other objects with different field logic with simple clicks. Lets jump into the solution, we will use flow to check duplicate record logic and use apex trigger to initiate the Flow whenever a record is created or updated. Visual Work Flow : [Click] First we will create the Flow to check the duplicate records based on the name and store the result in the variable. In this example, we will use the Account object for the dupe check. Step 1  : Create a new visual flow with the Name ‘ DuplicateAccountCheck ' Step 2  : Click and drag the RecordLookup into t

Plan your Dreamforce with “Dreamforce Trail”

Salesforce has many good resources for anybody looking to begin Salesforce as beginner, Intermediate or Advanced. Trailhead is also one among the good resource to learn salesforce and my favorite too. I have also written blog post about Trailhead & my favorite module   This  blog post covers an interesting and helpful Trailhead module. Yes Its all about ' Dreamforce Trail ', if you are a Dreamforce Attendee, then I strongly recommend you to take a look into this Trailhead module. No Admin skill or No Developer skill is required for this module.Start winning Badges and is gamified so it motivates you to reach more badges and finally you end up gaining knowledge on Salesforce. Why do we have Dreamforce Trail module in Trailhead?  To help people who is coming to dreamforce for the first time and to plan well for the events. Dreamforce is a tech feast for anybody. Dreamforce is salesforce festival. If you don’t plan well, you will miss something highly helpful . This Dre