“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:
- Click the Export Details button
- Choose Comma Delimited .csv as the export file format
- Click Export button
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.
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.
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).
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!– | |
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); |
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!
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.
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!
- Talend
- MuleSoft
- Convergence by Trinisys
- Jitterbit
- Informatica
- InfoSphere DataStage by IBM
- Dell Boomi
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!
Nice article but it would be more interesting to see what is working in Lightning (e.g. report export does not work there).
LikeLiked by 1 person
Hi Thomas,
Thanks for the feedback. You are correct, many report capabilities such as export is not yet supported in Lightning Experience. I encourage you to vote up the idea here: https://success.salesforce.com/ideaView?id=08730000000Lg0dAAC
Reports & Dashboards: Lightning Experience Limitations (Winter ’16)
http://docs.releasenotes.salesforce.com/en-us/winter16/release-notes/lex_gaps_limitations_analytics.htm
Doug
LikeLike
Hi Thomas,
The Summer ’16 release notes (safe harbor) add ability to export reports in Lightning Experience.
https://releasenotes.docs.salesforce.com/en-us/summer16/release-notes/rn_rd_reports_dashboards_export.htm
Doug
LikeLike
Great post! Didn’t know some of the options. Thanks Doug!
LikeLiked by 1 person
Thanks Alba!
LikeLike
One more free and powerful service for exporting Salesforce data to CSV – https://skyvia.com/data-integration/salesforce-data-loader
LikeLiked by 1 person
I completely agree with Sergei, Skyvia is really cool tool
LikeLike
How would i export data of my lightning component to Excel?
LikeLiked by 1 person
Hi Vaibhav,
Disclaimer, I haven’t done much with lightning components. But considering it’s a JavaScript app-thingy, I’d simply provide a link to a visualforce page that exports the data to .csv.
If you’re wanting to let the user just download as .csv data in an HTML table rendered in your component then you might try a JavaScript library that provides that functionality. But I’d still go the visualforce link route personally.
Thanks,
Doug
LikeLike
Thanks for posting that Doug, there’s some really useful information in there.
Yesterday I was looking for a way to copy query results from the dev console and paste to Excel and came across a reply on StackExchange that I have written up on my own site (so that I can find it easily next time I need it and have forgotten 🙂 ) – http://www.mikearthur.net/copy-query-results-from-Salesforce-Developer-Console
Thanks,
Mike.
LikeLiked by 1 person
Neat trick, Mike. I wish the developer console had an easy way to export the table data — I mean, the data is right there! haha As you mentioned in your post, I use workbench as a workaround a lot if i’m just wanting to run quick queries.
LikeLike
Curious why you left Data Export out of the list…
Setup > Administration Setup > Data Management > Data Export
LikeLiked by 1 person
No reason. But now I feel a bit foolish for having left it out. I’ve updated this post to include the Data Export option. Thanks!
LikeLiked by 1 person
cool. I suspected it was since it was mainly designed for backups. Sometimes also it’s the trees obscuring the forrest. 🙂
LikeLiked by 1 person
Hi Doug,
Great post. I have chosen to go ahead with Option 7. Apex.
I wanted to put two kinds of data into two different sheets of an excel. Is that doable with this approach?
Regards,
Vaishali
LikeLiked by 1 person
Hi Vaishali,
Thanks for the kind feedback! Supposedly it is possible to create multiple worksheets of an excel workbook if your visualforce page outputs the Office XML of the document. Here are a couple blog posts showing how:
https://eltoro.secure.force.com/CreateExcelFilesWithMultipleTabs
http://appirio.com/tech-blog/how-to-create-a-multi-sheet-excel-workbook-from-apex
Hope that helps!
Doug
LikeLike
Hi Doug,
I am complete data beginner. Perhaps you can help me.
I am trying to export all of my data from Salesforce to Pipedrive.
Pipedrive has a good format for uploading: http://support.pipedrive.com/hc/en-us/articles/208039595-Importing-Data-with-spreadsheets#C1
However, I cannot seem to get the data exported in the way that is needed.
The full data export from salesforce creates many separate files, which is good to have, but not for uploading to pipedrive.
Setup > Administration Setup > Data Management > Data Export
Salesforce only allows me up to 50 records when I Run a Report.
I’ve had no success with skyvia or dataloader.io
Perhaps these would work but I cannot seem to output the data in any workable way to fit the pipedrive format required.
I simply want my account, contact, opportunities and activities in one file.
Do you think you can help me? Is this possible?
Thanks for your consideration,
Ray
LikeLiked by 1 person
Hi Ray,
I’ll be completely honest with you. I’m not sure I feel comfortable importing data from Salesforce into Pipedrive since it appears to be a CRM competitor =^P
Are you really needing ALL of your Salesforce org’s data somehow imported into Pipedrive or just Contacts and Leads?
To get started, you might try and run a Salesforce Contact report to export the desired fields (name, account name, email, phone, address) then try using Pipedrive uploader to map the columns from your .csv report export to the Pipedrive fields.
If you have hundreds of thousands to millions of records, I’m not sure the Pipedrive capability, but you would need to consider exporting the data with Salesforce’s Data Loader using Bulk API.
If you really need lots and lots of your Salesforce data imported to Pipedrive (dozens of objects, hundreds of thousands of rows) then you may want to consider an ETL solution like Talend or Mulesoft.
Doug
LikeLike
Hi Doug,
That’s fair.
It’s not that many records. I would just be nice to have the each deal associated with the right contacts and activities. This way I can look back to customer request and conversations. Also there are contacts not associated to any deal, just a specific account.
My reports only output a maximum of 50 records (I assume that’s based on my edition of SF).
I do not personally have the capabilities of correctly using a bulk API process.
I think I will attempt to upload the accounts, opps, contacts spread sheets (in that order).
Hopefully I can match as many records as possible. If I ever need to go back in history I will just search the spreadsheets.
Regardless, thank you very much for your response.
LikeLiked by 1 person
Hi Ray,
Seeing only 50 records sounds fishy to me. My guess is perhaps you’re still in the report builder where only a preview of records are shown? When designing the report, make sure to click the Run Report button as well as the Show filter be set to All Records and not just My Records (might say My Accounts or My Contacts).
https://help.salesforce.com/articleView?id=reports_builder_editing.htm&type=0&language=en_US
LikeLike
Thanks Doug. That helped, I appreciate the advice. Definitely a rookie mistake.
LikeLiked by 1 person
No worries, glad to help!
LikeLike
Doug,
I’m trying out Option 6 in Lightning and It works fine except for checkbox fields. How do I get a value in Excel rather than a picture of a checkbox?
Eric
LikeLiked by 1 person
Hi Eric, as workaround you might try formula field that displays desired value when checkbox is true or false. Though I’ve heard rumors formula fields in Lightning might not be supported for Excel exports, but try it to be sure. If that doesn’t work then try having another custom field like a text or picklist and use Process Builder or Workflows to set value in it when checkbox field changes.
Doug
LikeLiked by 1 person
The formula field worked for my use case. Thanks Doug.
LikeLiked by 1 person
I’d love to have you take a look at what I’ve been up to with Excel and Salesforce. Feel free to request a free trial copy.
https://ericsplayground.wordpress.com/home/documentation/
LikeLiked by 1 person
Hello Doug,
first of all, Thanks for this great share. I would like to test the solution 7 but the apex example code is gone (?)
regards,
LikeLiked by 1 person
Hi Rok,
I recently changed the code snippet to be a gist and apparently those don’t render on mobile.
I’ll revise the post so code is shown again.
In meantime, see code samples here:
gist.github.com/DouglasCAyers/c733b60db61c290b95ff0047ab3d2432
gist.github.com/DouglasCAyers/1b103b1eb6e2dc8c167c8112ef686d36
LikeLike
God bless you Doug. Answer 1 hour later. many thanks 😉
LikeLiked by 1 person
Hello Doug (again),
How can we add as code to have export file in UTF-8 format? (7. Apex)
Thanks in advance.
LikeLiked by 1 person
Hi Rok,
As far as I know, I believe the default character set for String fields on SObjects is UTF-8.
The ContentVersion object to my knowledge does not let you specify the character set but you might be able to with Attachment object: http://salesforce.stackexchange.com/questions/16157/attachment-utf-8-character-set
The only method in Apex I know of that lets you specify a character set is with EncodingUtil.urlEncode( inputString, charset ). You might try that, but that will URL encode the special characters which you might not want, or perhaps encode/decode it back to back and see if that somehow converts the string to your desired character set.
Doug
LikeLike
Flatly allows auto-export of Salesforce data to several cloud drives -including OneDrive, as XLSX or CSV. It runs as frequently as every 10 minutes. Flatly.IO – Disclosure: I work at Flatly.
LikeLiked by 1 person
This article is extremely helpful. Thanks, Doug. One more tool to add to the ETL list is Pragmatic Work’s Task Factory add-in for SQL Server Integration Services which contains Salesforce source and destination components.
http://pragmaticworks.com/Products/Task-Factory
http://help.pragmaticworks.com/taskfactory/Index.html?SalesForcecom.html
LikeLike
Is there size or memory limits to writing to a file? I came across an issue where I was told that there is a 6MB cap on memory and when downloading large amounts of data, many files are created. Is there a workaround to create a single file instead of many for say 10000+ records?
LikeLiked by 1 person
Hi Anand,
Yes, there is a 6MB heap (memory) limit in Apex. You can learn more about this and others at Execution Governor Limits.
Apex is good for generating relatively small data sets. If you need generate data for tens of thousands or more records then I recommend using Reports or ETL tool to export the data.
Doug
LikeLike
Hello Doug,
Is there any way to create the multiple worksheets in the same excel file with all the input controls. wanted to include input controls(e.g Inputtext, checkbox , command button) in worksheets through apex
Tried with the below approach specified in the below link but it does not allow me to include input controles in excel XML. It says tag needs to be included. I added that but when i downloaded, lost the formatting of excel, showing the onlly data
http://appirio.com/tech-blog/how-to-create-a-multi-sheet-excel-workbook-from-apex
Kindly suggest any other approaches to achieve the same?
Regards,
Pardha
LikeLike
Hi Pardha,
I’ve never attempted to generate Excel with multiple worksheets from Visualforce. Perhaps try asking on https://salesforce.stackexchange.com.
Good luck! And if you figure it out perhaps consider blogging to teach others how =)
Doug
LikeLike
Hi,
Nice article with cool code snippets.
A free tool that will allow to create joins on multiple objects is Microsoft’s power query addon for Excel:
https://powerbi.microsoft.com/en-us/blog/announcing-power-query-support-for-salesforce-com/
gl,
Siech
LikeLiked by 1 person
Some good options here, however all seem to require a download of a csv. Plainly this option is not so great when the data you are downloading contains personal data.
Has anyone had any experience with implementing an API export/sync of specific object data to AWS?
This on the face of it seems to give a beautiful solution. Data exported in realtime/on demand, into whatever database/storage device you want, allowing both easier reporting/graphing and escaping the expensive and easily exceeded Salesforce data storage limitations.
LikeLike
Is it possible to export specific fields using my own aliases from salesforce into CSV File?Right now I spend a lot of time trying their data loader but it does not recognize aliases and I need to use aliases. Do you know if it is possible? I wrote my own query since I don’t want all the fields in Salesforce Objects. Please advise. Thanks
LikeLiked by 1 person
Hi Peace,
No, when querying records from Salesforce API you must use the API field names. Once the data is exported, you can manipulate the column names using a spreadsheet program, an ETL tool, or other logic in your app.
Doug
LikeLike
What an awesome article!
LikeLiked by 1 person
Thanks Simba!
LikeLike
Hi Doug. Very informative article.
LikeLiked by 1 person
Thanks, Greg! Glad you like it
LikeLike
When you say the export files expire in 48 hours, does that mean you have to download the zip file within the 48 hours or also unzip the file in that timeframe?
LikeLiked by 1 person
Hi Heidi, you have 48 hours to download the zip files after receiving the email from Salesforce else the links expire. Once downloaded, the zip files last forever. I usually archive the zip files as is and only unzip them if I need to access the data within them.
LikeLike
Thanks for the article Doug. I have to do a monthly export of about 10 reports , midnight of last day of each month. Is there any appexchange product or any particular way in Salesforce to have these reports exported in csv format and emailed to me or well, stored as chatter files/ documents which i can open in the morning and work. Thanks
LikeLiked by 1 person
Hi Sumi,
There’s likely some apps on the AppExchange to help with scheduled reports, but I’m not familiar with any.
You might also be interested to try my free open source app Mass Action Scheduler that allows you to schedule a report then process the records (e.g. run each record through process builder, a flow, etc. or create a case for each record, or invoke apex).
Good luck!
LikeLike
Hi Doug, this post is great, I currently using Mulesoft (custom application ) and handling export with data bigger than 6 million records, wondering if there’s any service / provider that ensures exports with high availability, meaning sometimes I’m have stoppers because limits mainly.
LikeLiked by 1 person
Hi Doug,
We’ve built one more tool to export all of your data to CSV. I think it’s the fastest way to export all your data. You run one command (and authenticate using OAuth if it’s the first time running it). I’d love to get your feedback.
https://www.octoberswimmer.com/ro-backup/
LikeLike
Doug, does the writing to a Chatter file still work? In lightning, does it just show up in the general “Files” area?
LikeLike
Yes, they are in the files area, jut worked for me. Thanks Doug, great post
LikeLike
Doug, great article – thank you. I am trying to run data loader cmd line but running into errors
LikeLike
Great Doug, though I am able to create a CSV file, but I also want to add few more rows to the same existing CSV file or append more lines to the existing CSV file. Could you please suggest.
LikeLike
Thank you for this amazing article. I learnt something new today.
LikeLiked by 1 person
As an alternative ETL tool, I’d like to mention Skyvia. It allows us to export Salesforce data as CSV file (https://skyvia.com/data-integration/salesforce-csv-file-import-and-export) easily without coding.
LikeLike