Overview

In this tutorial, we will see how CloudFiles can be used with Salesforce flow automations to check if a document is signed and authenticated . Each time a file is uploaded into Salesforce or external storage, the following actions will occur:

  • The file is processed using CloudFiles Document AI.
  • A Natural Language Query runs to detect the presence of a signature .
  • The related Salesforce record is updated to reflect whether the signature is present or not.

In order to setup this automation, you first need to have some pre-requisites. After this you can start setting up some query 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

Initial Automation Setup

There are 2 flows you will need to setup to process the uploaded files. The first flow is triggered when the document is uploaded into Salesforce or external storage. This flow sends the file to AI for processing. This might take a few seconds. Once the AI is done with processing, the second flow will trigger which will contain the processed document. You can then run queries on this processed document.

  • Flow 1: Send Document For Processing - Triggered when file is uploaded into Salesforce or external storage. Sends the file for processing which may take a few seconds to a minute.
  • Flow 2: Document Processing Complete - Triggered when the file has been processed by AI. Performs queries on the file to extract the data.

Read the article on AI Flows - Initial Setup Guide carefully to setup both the flows. Once your initial flows are setup as shown above, you are ready to move to the next step.

Once your flow setup is complete, your flows should look like the following.

Query Automation Setup

Now that you have the initial automation setup, we can take the document processed flow and extend it to query the document and update the required fields. In this section, we show how to query the processed document, check the results and perform the necessary updates.

Querying the document

In order to query the document, we will simply use the Query Document/Dataset flow action. This action taken in a processed document ID and a text query as input. The processed document ID is available as output of the Get Event Details action. Here are the full inputs used in the image below.

Processed Document Id :

( {!Get_Triggering_Event_Details.DocumentProcessed.ProcessedDocumentId} )

Query = Enter a clear Natural Language Classification Prompt such as:

Check if a valid signature from a doctor is present in the given document. A valid signature may be handwritten or digital and is typically located near the bottom or in a designated section of the document. It may also be accompanied by identifying information such as the doctor’s name, designation, or license number. Return 'Yes' if a valid signature from a doctor is present, otherwise return 'No'.

Example:

Suppose a medical prescription, as shown below, is uploaded to the Files section of the corresponding record.To verify the authenticity of the document, we use the following query:

"Check if the document contains a valid doctor's signature. Return 'Yes' if a valid signature is present; otherwise, return 'No'."

This query helps determine whether the document is verified based on the presence of a valid signature. The AI Output for this document is 'Yes'.

This query helps determine whether the document is verified based on the presence of a valid signature. The AI Output for this document is 'Yes'.

Check AI Output and Update the Record

The Query Document action returns text variables as the AI's response to the input query. If the response is Yes, indicating the document is verified, proceed to identify the correct Patient Record record. To do this, compare the β€˜Id’ with the β€˜Context’. In order to do so use Id Equals Outputs from Get Processed Event Details > DocumentProcessed > Context field-value pair to filter contact records in β€˜Update Records’.

See it in Action

Now that everything is set up, you can test your flows. When a medical form or prescription is uploaded into a Medical form record, the verfied status is updated if a valid signature is present.

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.

Flow 2 Debug

Whenever a file is processed using the Process Document using AI action, a Document Processed object record is published.

You can query these event object records to verify successful file processing and debug the flow.

Example SOQL Query:

To check Document Processed events sorted by the most recent:

SELECT Id, Name, CreatedDate, cldfs__Data__c 
FROM cldfs__CloudFilesEvent__c 
WHERE cldfs__Type__c = 'document-processed' 
ORDER BY CreatedDate DESC

You can check the Context and File Details in the Data Field of the record.

When a flow runs in debug mode and executes Query Document/Dataset actions, you can check the results and modify the queries if required.

SELECT Id, Name, CreatedDate, cldfs__Data__c 
FROM cldfs__CloudFilesEvent__c 
WHERE cldfs__Type__c = 'document-processed' 
ORDER BY CreatedDate DESC

You can check the Context and File Details in the Data Field of the record. When a flow runs in debug mode and executes Query Document/Dataset actions, you can check the results and modify the queries if required.