Skip to main content

Exporting Files/Attachments from Salesforce

While working on a Salesforce migration project where I was asked to export a set of attachments from one Salesforce Org to another, I developed this tool. The customer had millions of attachments in their source Org and only a few thousands had to be migrated.

What are the existing options in the market?

Few of the existing options suggested by different people were:
  1. Use Weekly Export. I could use it but I only had to export a few thousand attachments from millions and I can only run it once a week.
  2. Use dataloader.io. The free version only allows me to extract limited records on a day.

Where can I download this from?

I developed a JAR file which did the job for me and wanted to share it with everyone. 

Download URL: https://www.crossdoor.io/sfdcfiles/

There are 2 files
  1. build.properties
  2. SFDCFiles.jar
First step is to setup build.properties with the Org credentials and SOQL to extract data from.

How to run this?

To run this Jar file execute the below command on your terminal/command prompt:

java -jar SFDCFiles.jar

Make sure you are able to run the Jar files on your terminal/command prompt i.e. you have Java setup on your machine. 

What are the use cases it covers?

Use Cases you can cover using this tool:

Use Case 1: Extract all the attachments related to accounts. To achieve this you can set the query in build.properties to "Select Id, Body, Name from Attachment Where ParentId in (Select Id from Account)"

Use Case 2: Extract all the attachments from a given set of attachment ids. Add the attachment Ids in the "source.csv" and set the query to "Select Id, Body, Name from Attachment". This will download the attachments listed in source.csv and the fields listed in the query will be added to extract.csv.

How smart is this?

If you have started to extract a huge number of files which is taking hours and you lose your internet connection, don't worry, when you restart your process, it skips the files it already finds extracted in your extract.csv. Nice!!

"build.properties" explained

username=gulshan@myusername.com
password=password+token
serverURL=https://test.salesforce.com
Login credentials of the Salesforce Org

extractFolderPath=/Users/gulshanmiddha/Desktop/sfdcFiles/
This is the absolute path of the folder where the Jar file is placed and the file extract will happen.

extractFileName=extract.csv
CSV file name where the data will be extracted

sourceFile=source.csv
If the files have to be extracted from the given set of Ids, add the Ids in the source CSV and specify the name here.

query=Select Id, Body from Attachment Where ParentId in (Select Id from Account)
SOQL with the blob field and other columns, all these columns will be added to the extractCSV

blobFieldName=Body
Field name which holds the blob value of the file, this has to be added in the above SOQL

nameFieldName=Name
Field Name from SOQL which consist the File Name, this has to be added in the above SOQL. Files extracted are named in a format i.e. ID_NAME. This is to handle the cases where there is more than 1 file with the same name.

Note: I am using standard SOAP API with a batch size of 1, so you'll notice it extracts one file at a time. I tried using Bulk API but due to some issues, its not working for now.

Comments

  1. Hi Gulshan, its great utility and does save a lot of time.
    Thanks for getting it together.

    I was wondering could a version of this work for another scenario where Attachments from Salesforce are to be synchronised with an external system (like an ERP) ? Considering there is no Middleware.

    Thanks
    Nikhil

    ReplyDelete
  2. Hello from Canada. This utility is great. Thank-you very much for providing it. I have a salesforce org that has some attachments with odd filenames (for example, one that includes "C:\" in the name of the file, causing a write error in Windows). Would you be able to share the source code to this tool (provide a github repository or similar)? Is so, I'd be interested in making such fixes so that these types of odd attachments are handled gracefully and sharing the code changes back.

    ReplyDelete
  3. You can try https://www.sfdcfileexporter.com/sffxhome/

    ReplyDelete

Post a Comment

Popular posts from this blog

Autocomplete Lookups for Salesforce1

We all are seeing that Salesforce1 is evolving with every passing day and there is yet lot to be done. One of the many items is a custom lookup field on a Visualforce page. Lightning design systems do provide us with the CSS we can use to create lookup fields the logic has to be written by the developer. Below is a basic example that can be used to implement the basic autocomplete version of the lookup field. The auto complete text box is implemented using the CSS provided by Salesforce1  lightning design . The Visualforce page uses Visualforce remoting to fetch records based on the user input. A call to the controller method is made every time a keyup event is fired and the results are updated.

DumpIT - Migrate / Clone Salesforce Org - Data

How complicated can it be to clone data from one Salesforce Org to another? It can take from minutes to weeks depending on the number of objects and relationships between them. I am glad to share a tool I developed which may save you a lot of time. DumpIT comes as an executable jar file which helps to clone data from one Salesforce Org to another. Recently Salesforce released a feature to clone a Sandbox but it has its own limitations and cannot always be used. How to use DumpIT? Prerequisite - You must have Java installed and setup on your local machine. Try running "Java -v" command on your command prompt to make sure its all setup and working.  Step 1: Download the tool Download the tool from this link https://crossdoor.io/dumpit/ Create a folder on your local machine and place all the three downloaded items in that folder. You will see these three items: results folder: Success and Error files are placed on this folder on execution, for each object. You can