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.
Download URL: https://www.crossdoor.io/sfdcfiles/
There are 2 files
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.
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.
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.
What are the existing options in the market?
Few of the existing options suggested by different people were:- 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.
- 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
- build.properties
- SFDCFiles.jar
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.compassword=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.
Hi Gulshan, its great utility and does save a lot of time.
ReplyDeleteThanks 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
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.
ReplyDeleteYou can try https://www.sfdcfileexporter.com/sffxhome/
ReplyDelete