“If it’s not in Salesforce, then it doesn’t exist.”

The beloved phrase all Salesforce admins eventually learn and evangelize when training users to log their data and activities into Salesforce so that manager reports can show meaningful metrics. I mean, how else can you run automation workflow and lovely reports if there’s no data?

And that’s great, you got the data into Salesforce, but what about getting the data out?

Maybe you need to backup your data?
Maybe you need it for integration to another system?
Maybe you just love to play with spreadsheets (no judgements here!)

Whatever the reason, I’ll show you some easy ways to export your data to .csv!

I have grouped the options into four categories. Each have their merits and balance between cost, complexity, and versatility. Think of this as you’ve walked into a hardware store and you’re seeing all the various tools at your disposal. Sometimes you need a hammer, sometimes you need a jack-hammer.

  • Free Tools (household tools)
  • Code Your Own Tools (DYI projects)
  • Paid Tools (fancy multi-faceted tools)
  • ETL Tools (industrial power tools)

Free Tools

These won’t break the budget and generally do one thing very well and are easy to learn how to use.

1. Reports

The simplest option is to create a report then export the details as .csv. When viewing a report:

  1. Click the Export Details button
  2. Choose Comma Delimited .csv as the export file format
  3. Click Export button

reports-buttons-export-highlightreports-export-details-csv

2. Data Export

The next simplest way to mass export data to .csv is to use the Data Export scheduling tool. Mainly marketed as a data backup service built right into Salesforce, you can schedule to have some or all of your objects exported to individual .csv files to download in a .zip file. The administrator who schedules the export will receive an email with the link to download the files when they’re ready. Don’t delay, the files expire after 48 hours.

data-export-setup-screenshot

data-export-schedule-screenshot

3. Salesforce Data Loader

Tried-and-true, the Salesforce Data Loader has been the go-to tool for administrators needing to import or export data to/from Salesforce in .csv file format. It is officially developed and supported by Salesforce.

To download the tool, in Salesforce navigate to Setup | Data Management | Data Loader.

The tool gives you a nice user interface to pick the object and fields and criteria for the data you want to export, or write your own SOQL query. It also supports command line scripting if you wanted to automate a recurring export.

salesforce-data-loader-screenshot.png

4. dataloader.io

For a cloud-based alternative to the Salesforce Data Loader, check out http://dataloader.io/ by MuleSoft. It has a user interface for selecting the object and fields and criteria, or you can write your own SOQL query. This is another tried-and-true option for importing and exporting data in .csv format. A neat benefit is you can save data to your computer, Dropbox, Box, SFTP, or a database.

The free plan is more than enough for the average use case, but if you need to move more than 50,000 records a month then reasonable paid options exist too.

 

5. Workbench

Workbench, developed by Ryan Brainard, is a powerful, web-based suite of tools designed for administrators and developers to interact with Salesforce via the Force.com APIs. Workbench allows users to describe, query, manipulate, and migrate both data and metadata in Salesforce directly in their web browser with a simple and intuitive user interface. Although there are lots of things you can do with this tool, for our purposes in data export just navigate to Queries | SOQL Query after logging in.

You can, as with the other data loaders, pick the object and fields you want and the query is generated for you, or you can manually write your own SOQL query. Do note that the .csv option uses the Bulk API, so relationship fields can’t be used (e.g. if querying Contacts then you can’t query account.name field from related account — you would need to create formula fields on your object that pull that related data in and query the formula field directly instead, like account_name__c).

workbench-query-screenshot.png

Code Your Own Tools

For the inner programmer in you, it is possible to use Apex and/or Visualforce to generate .csv content.

6. Visualforce

I love Salesforce for this feature! Visualforce pages whose content creates an HTML table can be exported to Excel simply by setting the contentType attribute of the <apex:page> tag to “application/vnd.ms-excel#filename.xls”. Check out simple examples here and here. If you want to get fancy, you can use CSS to define the colors, font, and borders of the data when exported.

View Code


<!–
This page must be accessed with an Account ID in the URL.
For example: https://<salesforceInstance>/apex/ContactsCsvPage?id=001D000000JRBet
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_styling_content_type.htm
–>
<apex:page standardController='Account' contentType='application/vnd.ms-excel#contacts.xls'>
<apex:pageBlock title='Contacts'>
<apex:pageBlockTable value='{!account.Contacts}' var='contact'>
<apex:column value='{!contact.Name}'/>
<apex:column value='{!contact.MailingCity}'/>
<apex:column value='{!contact.Phone}'/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>

 

7. Apex

For experienced apex developers you may be thinking, “Hold it Doug, I know apex is fancy and all, but you can’t write directly to the output stream for the browser to download a file, so what dark arts are you proposing?”

True… you can’t (to my knowledge) write to the output stream in apex, but you can generate a comma-delimited string with a line for each record and save that as an attachment, chatter file, or static resource then reference that to download or email the content.

My personal choice is to save the data as a Chatter File because I don’t need a Salesforce record to serve as the parentId for an Attachment, and because Static Resources don’t allow DML so you have to use the Metadata API.

Here’s some sample code that creates a .csv file of 10 accounts. Copy and paste the below code in the Developer Console as anonymous apex then navigate to Chatter | Files. If you don’t see your new file, click on All Files on the left navigation.

View Code


String csv = 'Id,Name\n';
for ( List<Account> accts : [ SELECT id, name FROM Account LIMIT 10 ] ) {
for ( Account acct : accts ) {
csv += acct.id + ',' + acct.name.escapeCsv() + '\n';
}
}
ContentVersion file = new ContentVersion(
title = 'accounts.csv',
versionData = Blob.valueOf( csv ),
pathOnClient = '/accounts.csv'
);
insert file;
System.debug( file );


String csv = 'Id,Name\n';
for ( List<Account> accts : [ SELECT id, name FROM Account LIMIT 10 ] ) {
for ( Account acct : accts ) {
csv += acct.id + ',' + acct.name.escapeCsv() + '\n';
}
}
ContentVersion file = new ContentVersion(
title = 'accounts.csv',
versionData = Blob.valueOf( csv ),
pathOnClient = '/accounts.csv'
);
insert file;
System.debug( file );

chatter-file-csv.png
chatter-file-csv2.png

Paid Tools

The next two tools are powerful Excel add-ons to make your Salesforce users significantly more productive while working with Salesforce data directly within Excel. Exporting data is just one of the many multi-faceted functions these tools provide.

8. Enabler 4 Excel

This is paid tool and is available as an add-on to Excel or a Chrome extension for Google Sheets. Admittedly, this does way more than simply import or export data to Excel, such as pull data from reports, convert leads and merge records, and more. Within the Salesforce community, this has quickly been adopted as the successor of the original Connector for Excel. New features are released regularly, you should check it out!

enabler4excel-screenshot.png

9. X-Author by Apptus

This is a paid tool and is available as an Excel add-on. Admittedly, this does way more than simply import or export data to Excel. Apptus has developed a whole suite of features and solutions that all interoperate with each other. A powerful feature is ability to migrate data between Salesforce orgs; admins can setup templates to securely let users mass update data quickly; access Chatter within Microsoft Office apps, and more.

xauthor-screenshot.png

ETL Tools

Ok, a discussion about exporting data from Salesforce wouldn’t be complete without mentioning ETL tools. ETL stands for Extract-Transform-Load. These are developer tools and are more complicated to setup and use for the uninitiated than the other options already described. The below listed tools are not Salesforce specific but they do have adapters/connectors for working with Salesforce. Usually you see these deployed at enterprises or where customers need sophisticated integration between Salesforce and other systems. I’m just going to provide links here, enjoy!

How do you export to .csv?

Do you know of other tools or methods of exporting Salesforce data to .csv? I’d love to hear about it, please let me know in the comments below!

Thanks for reading!