Tutorials
Document AI Tutorials
Splitting multiple combined POs into child objects
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 cloudfiles document ai installation docid\ rfxciqrbejmpsmbczexam and configuration docid\ amnhmxwixyngnaxerbkwd are complete you have an active subscription or trial of cloudfiles document ai 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 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 docid\ cfegghvnwso7bcxyevrr 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 docid\ pwajwa0qo pxgqneurlln article this flow is based on the same structure outlined in the article, but instead of using the process document process document action, we are using the split document using ai 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 docid\ muam8ohdl70xumq9pmt96 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 docid jiiuobrwu1xxigbb3czc 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 docid jiiuobrwu1xxigbb3czc 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 docid\ cfegghvnwso7bcxyevrr 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 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