Flow Actions

Create Salesforce File

Introduction

The CloudFiles: Create Salesforce File flow action enables you to copy a file from external storage into Salesforce as a Salesforce File (Content Document). This action uses the file's metadata details as input to identify and retrieve the external file. Once executed, the action generates a corresponding Salesforce File, making it accessible and manageable within the Salesforce environment.

The image below provides a visual representation of the action, showcasing its input and output parameters. Detailed descriptions of these parameters are provided in the sections that follow.

Document image


What This Action Does

The CloudFiles: Create Salesforce File flow action enables copying an external storage file (identified/specified by its metadata) into Salesforce by creating a Salesforce File (Content Document) of the external storage file . For each such CloudFiles: Create Salesforce File action execution, a Content Version Created event is triggered on successful creation of the Salesforce File.

This action can be paired with other flow actions or elements to streamline processes such as:

  • Bringing external storage files into Salesforce for enhanced accessibility.
  • Enabling these files to be used in Salesforce-based automations (e.g., email workflows).
  • Allowing integration with external applications designed to work with Salesforce Files.

Example Use Case:

Suppose you've integrated external storage like SharePoint, where customer-related files (e.g., proposals, contracts) are stored in dedicated folders. You want to automate the process of emailing a selected file to all related contacts:

  1. File Selection: In a screen flow, present a list of file choices (e.g., file names mapped to file IDs) from the customer's folder.
  2. Input to Action: The selected file's metadata is passed into the Create Salesforce File action, which imports it into Salesforce as a Salesforce File.
  3. Trigger CloudFilesEvent Flow: The published Content Version Created event can link the file to the corresponding Salesforce Account using a Content Document Link.
  4. Email Automation: In a subsequent flow, fetch the file and email it as an attachment to the related contacts.

This action provides a seamless way to bring external files into Salesforce and leverage Salesforce's robust automation capabilities.

Input Parameters

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

DriveId

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.

You can get this parameter 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 like Get Connected Folder.

Library

The Library parameter is the external storage type you are using. Possible values are sharepoint, google (for Google Drive), onedrive, dropbox, box, cloudfiles (for AWS S3).

FileId

This is the ResourceId of the target file you wish to bring into Salesforce by creating a content Document/Salesforce File.

You can get this parameter by through other flow actions like Get Resource Details or by filtering Get Folder Contents

RecordId

The RecordId parameter is used to identify and manage the origin of a created Salesforce File when a Content Version Created Event is triggered.

Purpose:

  1. Event Identification: Helps distinguish the source of the event in scenarios where multiple flows use the same action for different objects or use cases.
  2. Content Document Linking: Enables creating a Content Document Link to associate the Salesforce File with a specific record.

Key Features:

  • Flexible Input: You can input any text string, not just a RecordId.
  • Event Output: Whatever you input here will be available in the corresponding event details as Parent Id
Document image


How It Works:

  • Input the RecordId of the relevant record into this parameter.
  • When the event is triggered, the RecordId is included in the event details.
  • In the CloudFiles Event Handler Flow Template event-triggered flow, retrieve the RecordId from the event details to filter and process further automations, such as linking the file to the record.

For example, If you want the created Salesforce File to be associated with an Account record, input the Account's RecordId into this parameter. In the event-triggered flow:

  1. Fetch the RecordId from the event details.
  2. Use the Content Document Link action to associate the created file with the Account.

This parameter ensures traceability and flexibility in handling files across different flows and use cases.

You can use this parameter not just to input a RecordId but literally any text string. Whatever, you input into the action shall be output in the corresponding Content Version Created .

If you need to create Salesforce Files linked to a Contact record but in two separate scenarios:

  1. Scenario 1: Input "Scenario1_ContactRecordId" as the parameter.
  2. Scenario 2: Input "Scenario2_ContactRecordId" as the parameter.

In the event-triggered flow:

  • Fetch the parameter value from the event details.
  • Use it to identify the Contact RecordId and differentiate between the two scenarios.

This approach allows you to:

  • Retrieve the Contact RecordId for further automation.
  • Differentiate between events to handle specific actions based on the scenario.

Output Parameters

The CloudFiles: Create Salesforce File apex action does not return anything as an output in the flow it is used but for every scuccesful flow action execution or the Salesforce File created a Content Version Created is published. This event signals the completion of Salesforce file/ ContentDocument creation and can be used to trigger platform event flows to perform post-creation actions.

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.