As many of you are aware, shortly (winter ’18) Salesforce will require all of its users to use Files as they are phasing out Attachments and Notes. While Salesforce is doing a nice job of releasing a tool in Summer ’17 to handle conversion of Attachments to Files, they still have not handled how to mass download all attachments from the system. This may be important to your org before going through the conversion process (or for any other reason). I know it is for mine.
My business case is actually two-fold:
- I need to get all of the attachments into a safe place before we do the conversion
- I need to get all of a specific type of attachment downloaded so that it can be uploaded elsewhere
While Salesforce does provide admins with the Data Export tool, the tool itself has a significant number of limitations. First and foremost, you can only run it once a week. Second, it downloads the files without the extensions and without the attachment name, essentially rendering them useless (at least for me). Lastly, you have zero control over which attachments are downloaded. In fact, since it is just a single checkbox option, you will get stuck downloading all attachments, documents, and files and that could lead to more headaches than anyone cares to deal with.
So with all of that said, I wrote up a nice design spec explaining what I was looking for and handed it off to my partner, who translated my design spec into a Python utility, and which is now available for all on GitHub.
The script is relatively straightforward. It goes through all of the attachments and downloads them to your local computer. The tool preserves the original filename and prefixes it with its Attachment ID. For my second business use case, I only needed attachments that were on Accounts, so an extra option exists to download Accounts Only attachments (by default it will download ALL attachments). As a bonus, there’s an option to ignore file names that contain certain keywords.
The script also creates a CSV file that maps the Parent ID to the attachment filename, so you could easily tell which file is associated with which account.
How to use the script:
- Make sure you have Python and pip installed
- Install simple-salesforce and requests
$ pip install simple-salesforce
$ pip install requests
- Download the tool from GitHub
- Open your CLI (Terminal/CMD) and run the following line:
- (Optional) If you want to download attachments belonging to Account only:
- (Optional) If you want to skip certain attachments:
Here’s a real-world example:
$ attachments_downloader.py -u firstname.lastname@example.org -p password -t sf9to5_super_secret_token -s /tmp/ --account-only --ignore photo demo upload
The command line above will download all attachments that belong to Account only and will skip any files which contain “photo”, “demo” or “upload” in their name.
- We tested it on Windows and macOS (Sierra) only (should work on Linux too)
- Ensure your macOS has the most recent OpenSSL library (use brew to upgrade) and that Python uses the most recent OpenSSL library. This is required for the tool to talk TLS with Salesforce
- Works on Production environments only
- Of course, make sure your user has the right permissions 🙂
Link to Mass Attachments Downloader tool:
I would love to get your feedback on whether you find this useful and if you have any questions. Thanks!