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
  4. The sequence is designed to steadiness excessive, low, odd, and even numbers. And on high of that, the wheels are different for European and American roulette. It’s not as sophisticated because it sounds although – a glance at|check out} the 2 variations you’ll come across beneath. An appropriately programmed digital laptop may give a convincing imitation of the behaviour produced by a human brain even if the brain 토토사이트 is a partially random machine.

    ReplyDelete

Post a Comment

Popular posts from this blog

Salesforce CPQ - Automatically add a Product to a Quote

Recently I have seen a question popping up on communities that how can we add a product dynamically to a quote (not within the bundle), based on a condition. I'll explain a few simple use cases below. These use cases refer to adding a product on a Quote Line Editor and the CPQ version installed is 214.6 Add a "Warranty" Product if "Macbook Pro" is added to the Quote. While I select "Macbook Pro" to add in my Quote, it should also add the "Warranty" product automatically to my Quote. 1. Product Rule : Create a Product Rule of type Selection and scope equals Quote.  Type: Selection Active: checked Conditions Met: All Scope: Quote Evaluation Event: Always 2. Error Condition : Add an error condition to the Product Rule. This product rule will run if this error condition returns true. As per the use case, it should run if there is a product added to the Quote with a Product code as "MBPRO" Tested Obje

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

DumpIT - Adding / Ignoring fields

Default settings for DumpIT, migrates data for all the creatable fields of an object. For example, if the build.properties file ONLY mentions account as: process.objects =Account This migrates all creatable fields for "Account" object. There ar scenarios where you want to migrate data for certain specific fields or ignore certain fields, to do so you can use these given properties in the build properties file. Ignoring field: To avoid migrating a certain set of fields, add the below-given property: Account.ignorefields =Industry,OwnerId This will migrate all the Account creatable fields except the ones mentioned in the above statement. Selective fields: To migrate data for only selective fields, add the below-given property: Account.fields = Name,BillingAddress,RecordTypeId In this scenario, only the fields mentioned in the above statement will be migrated, make sure you select all the required fields for that object.