How to automate download of weekly export service files

ErikP picture ErikP · Apr 16, 2012 · Viewed 20.1k times · Source

In SalesForce you can schedule up to weekly "backups"/dumps of your data here: Setup > Administration Setup > Data Management > Data Export

If you have a large Salesforce database there can be a significant number of files to be downloading by hand.

Does anyone have a best practice, tool, batch file, or trick to automate this process or make it a little less manual?

Answer

Adam Butler picture Adam Butler · Apr 17, 2012

Last time I checked, there was no way to access the backup file status (or actual files) over the API. I suspect they have made this process difficult to automate by design.

I use the Salesforce scheduler to prepare the files on a weekly basis, then I have a scheduled task that runs on a local server which downloads the files. Assuming you have the ability to automate/script some web requests, here are some steps you can use to download the files:

  1. Get an active salesforce session ID/token
    • enterprise API - login() SOAP method
  2. Get your organization ID ("org ID")
    • Setup > Company Profile > Company Information OR
    • use the enterprise API getUserInfo() SOAP call to retrieve your org ID
  3. Send an HTTP GET request to https://{your sf.com instance}.salesforce.com/ui/setup/export/DataExportPage/d?setupid=DataManagementExport
    • Set the request cookie as follows:
      • oid={your org ID}; sid={your session ID};
  4. Parse the resulting HTML for instances of <a href="/servlet/servlet.OrgExport?fileName=
    • (The filename begins after fileName=)
  5. Plug the file names into this URL to download (and save):
    • https://{your sf.com instance}.salesforce.com/servlet/servlet.OrgExport?fileName={filename}
    • Use the same cookie as in step 3 when downloading the files

This is by no means a best practice, but it gets the job done. It should go without saying that if they change the layout of the page in question, this probably won't work any more. Hope this helps.