Tutorials
...
Document AI Tutorials
AI Flows - Initial Setup Guide

Process Salesforce Files

overview in this tutorial, we will guide you on how to process salesforce files for document ai processing the files is a mandatory step that must be done before ai queries can be executed on a file processing makes the file ready for cloudfiles ai you will need to create 2 separate flows the first flow will trigger when the upload is done and will send the uploaded file to ai for processing the second flow will trigger when the document has finished processing and can now be queried process new document flow this flow sends any new file uploads for processing processing is an asynchronous operation and may take some time to complete document processing complete flow this flow executes when the document has been processed this is the flow in which you will actually add the query & response logic read the sections below carefully to setup these 2 flows pre requisites 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 process new document flow 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 processes each attached file using process document using ai docid 31ujx1ligtkwfkjuanbzt in the context of the triggering record successful file processing publishes a document processed docid\ xrr pnbpocwwcmyg6qgk9 event, triggering the document processing complete flow that is covered in the next section check the sub sections below for details on each of these steps create record triggered flow create a new record triggered flow with the triggering object type set as cldfs cloudfilesevent c additionally set some filter conditions this ensures that the flow is only triggered for the correct type of events e g using the below conditions, we will only trigger the flow when a new file is uploaded on contact records type ( cldfs type c ) = salesforce file attached include a run asynchronously path to access an external system after the original transaction for the triggering record is successfully committed here's how the trigger conditions would look like get event details now that we have trigger setup, we will get more details related to the event we will use the get event details action for this within in the run asynchronously path, add the get event details action under "set input values", toggle event (custom object) and select triggering cldfs cloudfilesevent c ( {!$record} ) loop through attached files since there might be multiple files attached, we will loop through all files and process each one seperately for this we use a loop element and choose the collection variable from the output of get event details {!get triggering event details salesforcefiles contentdocumentids} process each file in order to actually process the file, we simply use the process document flow action as shown below this action takes in 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 document processing complete flow this flow is triggered when the document we sent for processing in the flow above has finished processing we will use the document processed docid\ xrr pnbpocwwcmyg6qgk9 event along with a record triggered flow to intercept this we will then get the event details that will give us the triggering record and the processed document id that can be used later to perform ai queries on the document create record triggered flow create a new record triggered flow with the triggering object type set as cldfs cloudfilesevent c additionally set some filter conditions this ensures that the flow is only triggered for the correct type of events e g using the below conditions, we will only trigger the flow when a new file is uploaded on contact records type ( cldfs type c ) = document processed include a run asynchronously path to access an external system after the original transaction for the triggering record is successfully committed here's how the trigger conditions would look like get event details now that we have trigger setup, we will get more details related to the event we will use the get event details action for this within in the run asynchronously path, add the get event details action under "set input values", toggle event (custom object) and select triggering cldfs cloudfilesevent c ( {!$record} ) useful event information now that we have the event details of the document processed event, we can use this to get 2 useful pieces of information processed document id this will be used as an input to the query document action that has used in various other tutorials on document ai tutorials docid\ k89awfijxxjssysaajwcr context this is important to retrieve the record id or other important metadata that you want to pass when processing the document check the process each file section above to understand what is retrieved in the context output file details of the processed file specified in the input, which helps identify the file post processing what next? in this tutorial, we have only explained how to process a salesforce file so that it is ready for ai queries for actually understanding how automated queries can be performed and how the responses can be used to enrich salesforce data, check the other tutorials mentioned in the document ai tutorials docid\ k89awfijxxjssysaajwcr article