Flow Actions

Copy Salesforce Files

Introduction

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.

Document image


What This Action Does

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.

Document image


Input Parameters

Let us discuss each of the input parameters in detail in the sections below.

Content Document Ids

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.

Document image


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)

Destination Resource Parameters

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”.

1 - Library Input the destination Library. Possible values are sharepoint, google (for Google Drive), onedrive, dropbox, box, cloudfiles (for AWS S3).

2 - Drive Id 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.

Document image


3 - Folder Id 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.

Salesforce Record Id (Optional)

Input the object Record Id to which the Salesforce Files are attached.

This field is optional and you can pass any text value for this parameter. The passed value will be output in the salesforce-file-copied event details that will be published for every file copied using the Copy Salesforce File action as “ParentId”. If you leave it to null, the corresponding file copied events’ “ParentId” will also be null.

Output Parameters

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.

Document image


See It In Action

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.

Document image