Salesforce Org 2 Org File Transfer Using MuleSoft Composer

Meghesh Shenoy
Another Integration Blog
5 min readFeb 10, 2023

“Automate Anything, Empower Everyone, and Deliver Success Now”! You may have come cross these particular phrases recently. It makes sense because as of late, MuleSoft truly provides users with easy access to build and deliver End-to-End Automation. Now you can integrate legacy systems with modern day applications without writing a single line of code; allowing users to integrate multiple systems seamlessly.

Today we will take a deep dive into how, without writing a single line of code, we can transfer files between two different Salesforce Orgs quickly & seamlessly using MuleSoft Composer.

MuleSoft Composer is a part of the MuleSoft Automation package where admins, marketers, or any line of business users can build integrations swiftly without any prior coding or integration experience required.

But before designing the solution, as a good Trailblazer would do, let’s understand how Salesforce stores the files internally. Additionally, let’s take a look at how to access, upload, and download these files in Salesforce.

This is a diagram which represents the Object model of the Salesforce files storing mechanism.

These are the 4 different objects involved:

  1. Standard/Custom Objects(sObject)
  2. ContentVersion
  3. ContentDocument
  4. ContentDocumentLink

Let’s now understand what role each object plays:

  1. Standard/Custom Objects: Your Object can store any kind of data related to the organization. E.g., Account, Contacts or your Custom Objects.
  2. ContentVersion: Represents a specific version of a document in Salesforce CRM Content or Salesforce Files.
  3. ContentDocument: Represents a document that has been uploaded to a library in Salesforce CRM Content or Salesforce Files.
  4. ContentDocumentLink: Represents the link between a Salesforce CRM Content document, Salesforce file, or ContentNote and where it’s shared. For example a record of a particular Object.

Points to remember before starting to design our automation solution:

  • ContentVersion will store all the older and the latest version of the files.
  • ContentDocument is the Parent Object and will point me to the latest version Id of the file with LatestPublishedVersionId field
  • The Field present on ContentDocument Object : LatestPublishedVersionId = ContentVersionId
  • ContentVersionId is the record Id of the ContentVersion Object which will point me towards the latest version of the uploaded file
  • ContentDocumentLink Will be used to link my files with a particular object record.
  • Fields present on ContentDocumentLink Object: LinkedEntityType = Object RecordId & ContentDocumentId = recordId of the ContentDocument Object
  • Important point to note: whenever we use Salesforce Connector to get records it will always return a list of records, which means we need to use ForEach loop to access data in that list.
  • You can either go through these informative steps listed below or scroll down to watch the video of the automation containing a live demo of the automation.

Step 1: Query Account or your object in here. You can add any conditions according to your use case.

Step 2: Iterate out the List of retreived Accounts results.

Step 3: Retrieve all the ContentDocumentLink record related to your Object record in here. The LinkedEntityId standard field will store your Object record Id.

Step 4: Iterate over the retrieved list of ContentDocumentLink records retrieved from Step3

Step 5: Retrieve all the ContentDocument records related to your Object record in here. When looping over List of ContentDocumentLink records you can access the ContentDocumentId field in here

Step 6: Iterate over the retrieved list of ContentDocument records retrieved from Step 5

Step 7: Retrieve the record from the ContentVersion object containing the latest version of the file related to a record of standard/custom object using the LatestPublishedVersionId field present on the ContentDocument object. This will always store the record Id of the ContentVersion Object containing the latest of the file.

Step 7: We will now download the file by choosing the Action as Download file, Object Type as ContentVersion, and FileId which is the LatestPublishedVersionId.

Step 8: Iterate over the list of retrieved ContentVersion Object records.

Step 9: Upload the file in my new Salesforce instance by choosing the Action as Upload file and Object as Content Version & title, path same as that used in the source org.

When we upload a file in the background a new ContentVersion object record is created and this file is stored in that record.

With that, Salesforce will also automatically create a ContentDocument object record which will point towards the latest version of the file.

Step 10: Retrieve all the details of ContentVersion record that was created by Salesforce when uploading the file.

When we are fetching the details to access the newly created contentDocument record with the help of which we can link the file with my Salesforce custom/standard object

Step 10: Iterate over the list of retrieved ContentVersion Object records. We can now access the contentDocument recordId

Step 11: Once we have the contentDocumentId of the newly uploaded file in Salesforce we can link the file with your Salesforce standard/custom objects by creating a record of ContentDocumentLink.

And, there you have it! We have successfully automated the process of transferring files between two Salesforce Orgs, writing zero lines of code, all with the help of MuleSoft Composer. This is the true power of MuleSoft Automation — building integration solutions very easily.

--

--