TL;DR
Jump to GitHub for the complete repository: https://github.com/enreeco/sf-automatic-data-export-script/

Have you ever had a close relation with the Salesforce Data Export feature?

It’s a way to periodically export all Salesforce data set in zipped CSV files, including files and attachments.

You can do a one-shot export or schedule it on monthly (available on Developer Edition orgs) or weekly (available on Enterprise, Performance, and Unlimited Editions only).

The one-shot and periodic export configuration is straightforward:

  • Select the file encoding
  • Select which data you want to export (including files and content can increase export size)
  • Select a schedule (for monthyl or weekly export schedule only)
  • Select all or a subset of the available Salesforce objects
Monthly Data Export configuration schedule

What’s the outcome?

You’ll come up with a set of zipped files with a size up to 512 MB, containing Salesforce extracted files (if checked in configuration) or CSVs grouped by Salesforce objects, as shown below:

The struggle of downloading

What if you have plenty of files and want to automatically download them one-shot without having to click link by link?

Unfortunately there are no Salesforce standard APIs that you can use to automate the export and the only way was to go by script by getting all download links and triggering each download on a local folder (or remote storage if you are brave enough).

I thought there was already a solution out there but as far as I know there wasn’t anything.

The script

I decided to implement a script in NodeJS that:

  1. logs in to Salesforce with a full powered user
  2. opens the Data Export page
  3. looks for the download links (if any)
  4. triggers downloads one by one, putting them on a local folder

This way you can continue doing other tasks while the scripts runs.

DISCLAIMER: the script has been written in a quick & dirty style, so please don’t tell me it’s ugly, it gets you to the point!

Download it from GitHub: https://github.com/enreeco/sf-automatic-data-export-script

These are the simple steps:

  1. Install NodeJS and NPM if haven’t already (you just have do donwload the installers, follow this guide but you’ll find tons online)
  2. Open a console and install Foreman with:
    npm install -g foreman
    An alternative is to use the Heroku command line with:
    npm install -g heroku
  3. Install all required packages with command line npm install
  4. Rename the .env-local into .env and replace the environmental variables with a local path (where the files will be stored), the login URL, your username and the password+token
  5. Run your script with alternatively:
    nf start
    or
    heroku local

You’ll see the script running and the files magically will drop on the selected folder:

Automatica Data Export script execution

Have a nice Salesforce day!