Overview

In this tutorial, we will see how CloudFiles can be used with Salesforce flow automations to split multiple combined documents from an uploaded Salesforce file. Each time a file is uploaded into Salesforce, the following actions will occur:

  • The file is split using CloudFiles Document AI.
  • Child records are created for each split file.
  • The split file is then linked to its respective record.

In order to set up this automation, you first need to have some pre-requisites. After this you can start setting up AI automations and updates to achieve your use-case. Check the sections below for more information.

Pre-requisites

Before starting with this tutorial, you need to ensure that CloudFiles Document AI is properly installed & configured in your system. Additionally, you also need to create some initial automations to process the files before you can query them. Check the 2 sections below carefully -

Installation & Configuration

Ensure the following before starting:

  1. CloudFiles Document AI Installation and Configuration are complete.
  2. You have an Active Subscription or Trial of CloudFiles Document AI.
  3. The CloudFiles Event Mode setting is set to Custom Object

Automation Setup

In this use case, a file containing multiple purchase documents will be uploaded to an Account record. The file will be split into individual purchase orders, with separate records created for each PO. Finally, each split file will be attached to its corresponding record. The following three flows are required, to achieve this:

Flow 1: Send Document for Splitting - Triggered when a file is uploaded to Salesforce, this flow sends the file for AI-based splitting, which may take a few seconds to a minute.

Flow 2: Handling the Split Event - Triggered when the file has been split by AI, this flow processes the resulting parts to create corresponding child records.

Flow 3: Attach Files to Respective Records - Triggered when a new child record is created, this flow attaches the relevant split file segment to the respective record.

Send Document for Splitting

This flow is triggered automatically when Salesforce Files are uploaded or attached to an Account record. It uses CloudFiles Document AI to split the uploaded file into multiple documents, with each split representing an individual purchase order or document unit.

Setting up the trigger

Create a Record-Triggered Flow on the object cldfs__CloudFilesEvent__c, with the trigger condition: Type = salesforce-file-attached AND Object Type = Account. Enable the Run Asynchronously path.

Retrieve Event Details

Within the asynchronous path, use the Get Event Details action. Set the Event (Custom Object) to the Triggering cldfs__CloudFilesEvent__c {!$Record}.

The Outputs from Get Event Details > Salesforce Files Details will give you access to:

  • ContentDocumentIds - A list of uploaded or attached file IDs. ( {!Get_Event_Details.SalesforceFiles.ContentDocumentIds} )
  • ParentId – The Account record ID that the files were uploaded to. ( {!Get_Event_Details.SalesforceFiles.ParentId} )

These outputs will be used in the next step to split each uploaded file individually.

For more information refer to the Process Salesforce Files article. This flow is based on the same structure outlined in the article, but instead of using the Process Document action, we are using the Split Document Using AI action.

Split Attached Files

Next, add a Loop element to iterate through each ContentDocumentId retrieved from the Get Event Details step. This prepares the flow to split each uploaded file one by one.

Within the loop, add the Split Document using AI action. Configure it with following inputs:

  • File Id - Current Item from Loop ({!For_Every_Attached_Content_Document})
  • Library - type salesforce.
  • Context - select Outputs from Get Event Details > Salesforce Files Details > ParentId ( {!Get_Triggering_Event_Details.SalesforceFiles.ParentId} ).
  • You can also provide optional Instructions to guide the AI on how to split the file. For example: "This is a bundle of scanned purchase orders. Each purchase order starts with a bold header containing the name of the company or their logo. Split at each occurrence of this pattern and name them as the name of the company."

Each time this Split Document Using AI action is executed, CloudFiles processes the uploaded file, performs the split, and publishes a Document Split event once it's done. This event becomes the trigger for the next flow — Flow 2: Handling the Split Event.

For more information refer to the Split Document Using AI action.

Handling the Split Event

Once a file is successfully split using CloudFiles Document AI, a Document Split event is published. This flow is triggered by that event and is responsible for processing the resulting split files — creating child records (e.g., Purchase Orders) for each individual document segment.

After completing the flow setup, your flow should appear as shown below.

Setting up the trigger

Create a Record-Triggered Flow on the object cldfs__CloudFilesEvent__c, with the trigger condition: Type = document-split. Enable the Run Asynchronously path.

Retrieve Event Details

Within the asynchronous path, use the Get Event Details action. Set the Event (Custom Object) to the Triggering cldfs__CloudFilesEvent__c {!$Record}.

The Outputs from Get Event Details > Document Split will give you access to:

  • ContentVersionIds - A list of IDs of all the split files generated ( {!Get_Triggering_Event_details.DocumentSplit.ContentVersionIds} )
  • RecordId – The Account record ID ( passed as Context in Flow 1) ( {!Get_Event_Details.DocumentSplit.RecordId} )

These outputs will be used in the next step to split each uploaded file individually.

Process Created Files

Use a Get Records element to fetch all created ContentVersion records by matching Id In {!Get_Triggering_Event_details.DocumentSplit.ContentVersionIds}.

The Split Document Using AI action returns both the split files and the original merged file. The merged document, typically named Blank Page, should be filtered out to prevent the creation of unnecessary child records. This can be achieved by checking the file name and applying the appropriate condition.

Add a Loop element to iterate through the output ContentVersion record collection. For each record in the loop i.e. for each split file, respective Child Object records shall be created in the subsequent steps.

Configure Child Records

For each Content Version in the loop, configure a Single Child Record Variable and assign the following values:

  • For the relationship field on the Child Record (e.g., Account__c) , use: Outputs from Get Triggering Event Details > Document Split > RecordId {!Get_Triggering_Event_details.DocumentSplit.RecordId}
  • For the respective file reference field (e.g., Content_Document_Id__c), use: Current Item from Loop For Content Versions > ContentDocument ID > ContentDocument ID {!For_Content_Versions.ContentDocument.Id}

Add each assigned record to a Record Collection Variable. This approach supports bulk record creation while minimizing DML statements and reducing governor limit risk.

Create Child Records

After exiting the loop, use a Create Records action to insert all records stored in the collection variable. This creates one child record per split file.

Once the child records have been successfully created for each split document, the final step is to make those files accessible from the records themselves. Although each record stores a reference to its associated split file, a ContentDocumentLink must be created to display the file in the record's Files related list. This is handled in Flow 3: Attach Files to Respective Records.

Attach Files to Respective Records

This flow attaches each split document to the corresponding child record (e.g., Purchase Order). It reads the file reference (stored as ContentDocumentId) from the record and links the file using a standard Salesforce ContentDocumentLink.

Create a Record-Triggered Flow on the Child Object with the trigger condition that the file reference field (e.g., Content_Document_Id__c) is not null. This ensures the flow only runs for records that already contain a valid file reference.

Finally, add a create records element to create a ContentDocumentLink. The ContentDocumentId should be sourced from the record's file reference field, and the LinkedEntityId should be the record's ID {!$Record.Id}

Refer to the below image for more information:

With this final step, the automation is complete — transforming uploaded files into individually split, recorded, and attached documents within Salesforce.

Note

Note: As Flow Automation executions and document processing via AI may take a short time, the field updates will not reflect immediately. To view the updates, wait briefly and refresh the page.