Copy Salesforce Files
The Copy Salesforce Files flow action can be used in process automations where you have requirement to copy native Salesforce files to a desired location in external storage.
The image below gives an overview of the input parameters and what this action looks like. Detailed description of these input parameters and it’s outputs are provided in the following sections.
The Copy Salesforce Files flow action copies Salesforce files (identified by their content document IDs) to an external storage location (identified by its metadata). For each file copied, a salesforce-file-copied event is triggered on successful file copy.
This action can be combined with other flow actions or elements to automate processes, such as moving files attached to object records into their connected external storage folders. For instance, the flow snippet below demonstrates a use case where the Copy Salesforce Files action copies files attached to Account records (triggered by the salesforce-file-attached event) into their respective Account Folder (details provided by the Get Connected Folder action). Once each file is copied, a salesforce-file-copied event is published, providing the copied file details and enabling the file to be deleted from Salesforce after a successful copy. Refer to the Tutorial to understand the use case in detail. The image below illustrates how this automation would look.
Let us discuss each of the input parameters in detail in the sections below.
Input the Text Collection of Content Document Ids of Salesforce Files which are to be copied.
A Content Document represents a document that has been uploaded to a library in Salesforce CRM Content or Salesforce Files. The Content Document Id could be used to uniquely identify a Salesforce File.
One way of getting Content Documents Ids is by using Get Records flow action with Content Document Link as its object and by passing record Id of the desired record as LinkedEntityId. Refer to the article to know more about Content Document Ids.
This action cannot be used to copy “Attachments” (Salesforce Files old format)
These parameters are needed to specify the copy location. You can get these parameters by viewing metadata details for a folder in the “Content Library” tab of CloudFiles app in Salesforce or can be fetched through other flow actions or elements like “Get Connected Folder”.
Input the destination Library. Possible values are sharepoint, google, azure ,onedrive, dropbox, box, s3, sftp or cloudfiles .
This is important for Google Drive & Sharepoint libraries only. The Drive ID is a unique identifier for a storage location in both SharePoint and Google Drive. In SharePoint, it represents a document library within a site, while in Google Drive, it identifies a user's drive or shared drive.
This is the folder Id of the destination folder into which the files are to be copied.
If you wish to copy directly into a Drive instead of a folder, you can skip this parameter.
Input the object Record Id to which the Salesforce Files are attached.
You can use the Salesforce Record Id not just to input a RecordId but literally any text string. Whatever, you input into the action shall be output in the corresponding Salesforce File Copied event
If you need to differentiate the event based on type of Object and also in between two separate scenarios:
- Scenario 1: Input "Scenario1IdentifierTerm_RecordId" as the parameter.
- Scenario 2: Input "Scenario2IdentifierTerm_RecordId" as the parameter.
In the event-triggered flow, fetch the input parameter value from the event details, output as ParentId
This approach allows you to Retrieve the RecordId for further automation and Differentiate between events to handle specific actions based on the scenario.
The apex action does not return anything as an output in the flow it is used but for every file copied a salesforce-file-copied event is published. This event signals the completion of file copy and can be used to trigger platform event flows to perform post-copy actions such as deletion of files or updation of metadata.
If the action fails due to some reason an error-event event will be triggered and this event can be used in a decision element to diagnose and handle the error.
If a file is already present at the destination with the same name of the file which is being copied the handling of this conflict behaviour will be according to the preset configuration in CloudFiles app as shown in image below.
The GIF below demonstrates the example use case we discussed in prior section i.e. moving files attached to object records into their connected external storage folders. Refer to Tutorial to implement and understand the whole flow for this use case.