Overview

In this tutorial, you will build a CloudFiles Document AI workflow that keeps a student's admission checklist up to date. Each time a file is uploaded to a Student record, a record-triggered flow sends it to the workflow, which:

  • Classifies the file as one of the required admission documents, or as something else.
  • Finds the matching row on the Student's Document Checklist.
  • Marks that row as submitted, with the upload date.

A diploma uploaded to a Student, and the High School Diploma row on its Document Checklist marked submitted

The tutorial tracks five admission documents: Passport, High School Transcript, High School Diploma, English Test Score Report and Recommendation Letter. Swap in the documents your process needs; the steps stay the same.

Pre-requisites

Before you start, make sure that:

  • CloudFiles Document AI is installed and connected, with an active subscription or trial.
  • The CloudFiles Event Mode setting is set to Custom Object, so that uploads create CloudFiles Event records a flow can trigger on.
  • Your org has a Student object and a Document Checklist object below it, with one checklist row per required document.

CloudFiles Settings with the CloudFiles Event Mode set to Custom Object

This tutorial uses these fields on Document Checklist:

FieldTypePurpose
StudentMaster-Detail (Student)The Student the row belongs to
Document TypePicklistThe required document: Passport, High School Transcript, High School Diploma, English Test Score Report, Recommendation Letter
SubmittedCheckboxTicked when a matching document is uploaded
Upload DateDateThe day the document arrived
A Student record with five open Document Checklist rows and no files

Build the Workflow

The workflow does the classifying and the updating. Open the CloudFiles app, click the Document AI tab and choose Workflows. For everything a workflow can do, see Workflows.

Create the Workflow and its Launch Form

Click New workflow, name it Document Checklist and leave the review policy on Straight through, so the checklist is updated without a person approving each run. Under When this runs, it starts with, rename the document slot to uploaded_file and keep One document. Then click Add a field, name it student_id, keep the type Text and Required, and give it the label Student Id. The Salesforce flow fills both.

Creating the Document Checklist workflow and its launch form

Classify the Document

Click Add the first step and choose Classify. Name the step Classify the document and enter the labels Passport, High School Transcript, High School Diploma, English Test Score Report, Recommendation Letter, Other.

A Classify step with the five document types and Other as labels

Spell each label exactly like its Document Type picklist value. The next step looks up the checklist row by comparing the two, so a label that differs by a letter finds nothing.

Skip Other Documents

Add a Decision step named Skip other documents. Click Add branch, set the left value to the ai_classify_1.category chip, keep equals, type Other and leave then go to on End run. Every other file takes the no-match route to the next step.

Adding the Classify step and a Decision that ends the run for Other

Find the Checklist Row

On the no-match path, add Find a Salesforce record named Find the checklist row and choose the Document Checklist object. Keep All conditions (AND) and add two conditions:

FieldOperatorValue
Studentequalsthe trigger.student_id chip
Document Typeequalsthe ai_classify_1.category chip

Keep Only the first record. One step with two conditions finds the right row for every document type, so the workflow needs no branch per type.

A Find a Salesforce record step matching the Student and the Document Type

Check the Row Exists

Add a Decision named Is it on the checklist?. Add a branch with the left value sf_getRecords_1.outcome, equals and MATCHED, and leave the no-match route on End run. A Student without a row for that document type then ends cleanly instead of failing on the update.

A Decision that continues only when the Find step matched a row

Mark it Submitted

On the branch_1 path, add Update Salesforce record named Mark it submitted. Choose Document Checklist, set Record to update to the sf_getRecords_1.record.Id chip, and add two fields. Both values come from Global values under Values you can use here.

FieldValue
Submittedthe True chip
Upload Datethe Today chip
An Update Salesforce record step setting Submitted to True and Upload Date to Today

Always insert a value by clicking its chip. A reference typed by hand with a typo is saved as plain text, and the step then writes that text instead of the value.

The finished workflow looks like this.

The finished Document Checklist workflow on the canvas

Test and Publish the Workflow

Click Test run, upload a sample document, enter the Id of a test Student and click Start run. A test run writes to Salesforce exactly as a real run does, so use a Student you can change. The run shows what each step produced, with a confidence score for the classification. When the results look right, click Publish v1.

A test run on a sample transcript that marks the High School Transcript row submitted

Then go back to the Workflows list and click the Copy workflow ID icon in the Run column. The Salesforce flow uses this id to start the workflow.

The Workflows list with the published Document Checklist workflow

The flow needs the workflow ID from the Copy workflow ID icon. The Config API Name in the same list is used for moving configurations between orgs and is not accepted as a Workflow Id.

Start the Workflow from a Salesforce Flow

A record-triggered flow starts the workflow with the CloudFiles: Run Doc AI Workflow action whenever a file is uploaded to a Student. It listens for the Salesforce File Attached event, which CloudFiles records on the CloudFiles Event object whenever a file is attached to a record in Salesforce Files. The finished flow has four elements.

The finished record-triggered flow with four elements on the asynchronous path

Configure the Trigger

Create a Record-Triggered Flow on the CloudFiles Event object, triggered when A record is created and optimized for Actions and Related Records. Add two entry conditions: Type equals salesforce-file-attached and Object Type equals Student__c, the Student object's API name. Add a Run Asynchronously path and build everything below on it, because the workflow action makes an external callout that a record-triggered flow cannot make on the path that runs immediately.

The Start element on CloudFiles Event with the Type and Object Type conditions

Get the Event Details and the Uploaded File

Add the CloudFiles: Get Event Details action with the triggering CloudFiles Event record as its input. Then add a Get Records element named Get the uploaded file on Content Document, with the condition Content Document ID In Outputs from Get event details > SalesforceFiles > ContentDocumentIds, storing only the first record.

The Get Records element fetching the uploaded file by its id

Prepare the Workflow Inputs

Create five Apex-defined variables: Resource of class cldfs__Resource, slotBinding and SlotBindings of class cldfs__DocumentSlotBinding, and FieldValue_Single and FieldValue_Collection of class cldfs__FieldValue. Tick Allow multiple values on SlotBindings and FieldValue_Collection. Then add one Assignment with these rows, in this order.

VariableOperatorValue
Resource > libraryEqualssalesforce
Resource > idEqualsContent Document from Get the uploaded file > Content Document ID
slotBinding > resourceEqualsResource
slotBinding > slotEqualsuploaded_file
SlotBindingsAddslotBinding
FieldValue_Single > nameEqualsstudent_id
FieldValue_Single > valueEqualsOutputs from Get event details > SalesforceFiles > ParentId
FieldValue_CollectionAddFieldValue_Single
The Prepare the workflow inputs assignment

The slot name and the field name must match the names declared in the workflow exactly.

Run the Workflow

Add the CloudFiles: Run Doc AI Workflow action. Set Documents to {!SlotBindings}, Fields to {!FieldValue_Collection}, Record Id to Outputs from Get event details > SalesforceFiles > ParentId, and Workflow Id to the id you copied. Save the flow and activate it.

The Run Doc AI Workflow action with its four inputs

The action returns as soon as the run is accepted, and the workflow updates the checklist on its own a few seconds later. The flow does not receive the workflow's results.

Check the Run on the Doc AI Run Object

Every run started from a flow is recorded on the CloudFiles Doc AI Run object. Open the CloudFiles DocAI Runs tab and choose the All Runs list view to see each run with its status. A run reads Completed when the workflow finished and Failed when it could not.

Open a run to see its status, the Student it ran for in Parent Record Id, the document it started with, which checklist row it updated and what each step produced, with confidence scores.

A completed run that classified an English test score report and updated its checklist row

See it in Action

Open a Student and upload a document from the Files related list. Wait a few seconds and refresh the page: the matching row on the Document Checklist is ticked, with today's date. Each document marks only its own row.

A Student with the High School Diploma and English Test Score Report rows marked submitted

Note: Flow executions and AI runs take a few seconds, so the checklist does not update immediately. Wait briefly and refresh.

Congratulations! You have built an AI-powered document checklist with a CloudFiles Document AI workflow and a Salesforce flow.