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 file 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 whenever a new salesforce file is uploaded or attached (identified by the salesforce file attached docid\ cnswhxyiaabekamvbfxon event) onto the records it splits the attached file using split document using ai docid\ muam8ohdl70xumq9pmt96 in the context of the triggering record setting up the trigger create a record triggered flow for the object cldfs cloudfilesevent c with a trigger condition where type = salesforce file attached configure a run asynchronously path and in this path, use the get event details action, toggle event (custom object) , and select triggering cldfs cloudfilesevent c finally, add a loop element to process each file in the collection variable from the output of get event details {!get triggering event details salesforcefiles contentdocumentids} 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 action, we are using the split document using ai action configure the split document action in this step, the document uploaded in salesforce is sent for splitting this action accepts the following parameters file id select 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} ) optionally, set instructions with special processing guidelines in this example we are using the following instruction to guide the ai 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 for more information refer to the split document using ai action handling the split event successful file splitting publishes a document split docid jiiuobrwu1xxigbb3czc event, which triggers this flow, allowing us to handle the split documents after completing the flow setup, your flow should appear as shown below setting up the trigger the record triggered flow for cldfs cloudfilesevent c is configured to trigger asynchronously on the document split event it retrieves event details through the get event details action by enabling the event (custom object ) toggle and selecting triggering cldfs cloudfilesevent c ( {!$record} ) retrieve and loop through split files since multiple files may be generated, first retrieve the list of contentversion ids of the created files from the event details next, use a get records element to fetch the corresponding contentversion object records, using the following contentversionids in {!get triggering event details documentsplit contentversionids} loop through the output record collection to filter out the merged file and create record collection variables for each split file filter out merged file 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 assign details to record variable in these steps, we'll create a record collection variable to handle bulk processing, store multiple records in memory, and enable a single dml operation, to improve performance and to reduce governor limit risks loop through each file (excluding the merged one) for each file, assign values to a single record variable {!cv ids record} file ids c = {!loop each id} account c = {!get triggering event details documentsplit recordid} create a record collection variable on the purchase order (po) record add the single record variable to the collection {!po recordvariable} add {!cv ids record} create records once the loop finishes, you now have a record collection variable containing the details of all valid split files use the create records action to create individual child records for each purchase order using this collection refer to the image below to see how to configure the create records action inputs attach files to respective records after creating the child purchase order records, in this flow we will attach the split documents to their respective records once your flow setup is complete, your flows should look like the following setting up the flow the file id is stored during the creation of child records, allowing us to reuse this id in the flow to ensure the correct file is attached follow the below steps create a record triggered flow for the purchase order object set filter condition file ids c is null false get contentdocumentid from the contentversion using file ids c = {!$record file ids c} create a contentdocumentlink with contentdocumentid < {!get content version contentdocument id} and linkedentityid < {!$record id} to attach the file to the purchase order refer to the below image for more information 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