Create Salesforce Files (Batch)
The CloudFiles: Create Salesforce Files (Batch) flow action allows you to copy multiple files from external storage into Salesforce as Salesforce Files (Content Documents) in a single action.
This action functions similarly to the Create Salesforce File flow action, which handles a single file, but the batch version processes multiple files at once. By using a collection of metadata details as input, the action identifies and retrieves external files and creates their corresponding Salesforce Files.
Once executed, the action makes all the Salesforce Files accessible and manageable within the Salesforce environment, streamlining bulk file operations and automations.
Below is a visual representation of the action, with detailed descriptions of its input and output parameters provided in the subsequent sections.
The CloudFiles: Create Salesforce Files (Batch) flow action enables copying multiple external storage files (identified by their metadata details) into Salesforce as Salesforce Files (Content Document) in one action. Once all files are successfully created in Salesforce, a Content Version Created Batch is published.
This action can be paired with other flow actions or elements to streamline processes such as:
- Bringing multiple external storage files into Salesforce for enhanced accessibility.
- Enabling bulk file operations within Salesforce-based automations (e.g., batch email workflows).
- Integrating with external applications designed to work with Salesforce Files.
Suppose you've integrated external storage like SharePoint, where multiple customer-related files (e.g., proposals, contracts) are stored in dedicated folders. You want to automate the process of importing these files into Salesforce and emailing them to all related contacts:
- File Selection: In a screen flow, display a list of file choices (e.g., file names mapped to file IDs) from the customer's folder. The user selects multiple files.
- Input to Action: Pass the selected files' metadata as a collection (as a collection of cldfs__Resource) into the Create Salesforce Files (Batch) action.
- Trigger CloudFiles Event Flow: Once all the files are successfully created, the published Content Version Created Batch can be used to link the files to the corresponding Salesforce Account using Content Document Links.
- Email Automation: In a subsequent flow, fetch the created Salesforce Files and email them as attachments to the related contacts.
This action simplifies the process of importing multiple files into Salesforce while leveraging its robust automation capabilities. The batch processing ensures efficiency by handling multiple files in one go, and the event-driven architecture supports further automation seamlessly.
Let us discuss each of the input parameters in detail in the sections below.
The Files parameter accepts a collection of File Resources (i.e., a collection of cldfs__Resource) that contain metadata details for all the files to be copied into Salesforce as Salesforce Files.
Steps to Configure the 'Files' Parameter
Use Case Example: You want to import all files from an Account folder in connected SharePoint into Salesforce.
Here’s how to configure the Files parameter for this scenario:
Step 1: Retrieve All Files in the Folder
- Use the Get Folder Contents action to fetch all files within the folder.
- The action returns a collection of cldfs__Resource items, each containing the required fields:
- DriveId: Identifies the external storage drive.
- Id: The unique file ID in the external storage system.
- Library: Specifies the storage type (e.g., SharePoint).
- Now, you have a collection of file resources representing all files in the folder.
Step 2: Pass the Files Collection to the Action
- Assign this collection of cldfs__Resource to the Files parameter of the Create Salesforce Files (Batch) action.
- This allows the action to process each file in the collection, copying them into Salesforce.
Example Snippet in a Flow:
- Use the Get Folder Contents action and store the output as a collection variable (e.g., FilesCollection).
- Pass FilesCollection into the Files parameter of the Create Salesforce Files (Batch) action.
The Salesforce Record Id parameter is used to identify and manage the origin of a created Salesforce Files when a Content Version Created Batch is published.
Purpose:
- Event Identification: Helps distinguish the source of the event in scenarios where multiple flows use the same action for different objects or use cases.
- Content Document Linking: Enables creating a Content Document Links to associate the Salesforce Files 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
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 Files to be associated with an Account record, input the Account's RecordId into this parameter. In the event-triggered flow:
- Fetch the RecordId from the event details.
- 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:
- Scenario 1: Input "Scenario1_ContactRecordId" as the parameter.
- 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.
The CloudFiles: Create Salesforce Files (Batch) apex action does not return anything as an output in the flow it is used but for every scuccesful flow action execution or once all the Salesforce Files created a Content Version Created Batch event is published. This event signals the completion of creationSalesforce Files/ ContentDocuments 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.