Query Document (Batch)
While using the Query Document flow action enables to execute a single Query on the data of a processed document, using CloudFiles: Query Document (Batch) flow action enables to execute multiple queries on the data of a processed document in a single action.
The CloudFiles: Query Document (Batch) action enables you to execute multiple queries (natural language or English-language prompts) simultaneously on the data of a processed document. The action processes all the queries in a single step and returns the results of all queries together in the action output.
Imagine you are processing KYC files uploaded to Contact object records. is action, you can:
- Using the Query Document flow action you can classify the uploaded document as a Driving License, Passport, or neither.
- Once classifed, the next step would be to extract all the relevant information, such as the Passport number, Name, issue date, expiry date etc. from the document.
- And then, update the corresponding fields on the Contact record.
- Classification Query:
- Prompt: "Check the type of file. If it's a Driving License, return 1; if it's a Passport, return 2; if neither, return 0."
- Based on the result (e.g., 2 for Passport), the flow decides the next steps.
- Decision Element:
- Using the query result, the flow branches into specific paths for each document type.
- Follow-Up Queries in a single CloudFiles: Query Document (Batch) action:
- For example, if the classification query returns 2 (Passport), the flow enters the "Is Passport" path and runs queries like:
- "Extract the passport number."
- "Extract the name on the passport."
- "Extract the Issue Date"
- "Extract the Expiry Date"
- Instead, of using multiple Query Document actions, you can use a single Query Document (Batch) action and extract results of all the queries in a single output.
By avoiding multiple Query Document actions within a flow and using a single Query Document (Batch) action you can build complex workflows that extract data from documents efficiently and avoid flow timeouts.
Let us discuss each of the input parameters in detail, in the sections below.
Input the Processed Document ID of the file on which you wish to execute the Queries.
The Processed Document ID is a unique identifier provided by CloudFiles that represents the data of a processed document.
How it is Generated ?
How to Retrieve It ?
- Use the Get Event Details flow action associated with the corresponding event to obtain the ID.
- Alternatively, if you need to execute queries on a Salesforce File later or on-demand:
- Store the file's Processed Document ID in a custom Content Version field.
- This allows you to query the document anytime, without relying on the event.
Note
The same Processed Document ID can be reused multiple times to reference the document and execute queries as needed.
The Prompts input parameter is a collection variable (Apex-Defined type of Apex Class = cldfs__QueryDocumentPrompt) containing all the queries to execute on the file identified by the Processed Document ID.
Steps to Configure Prompts
For each query, create a separate prompt variable.
1 - Create Individual Prompt Variables For each query, create a separate prompt variable. Example Use Case: Extract four details (Passport Number, Name, Issue Date, Expiry Date) from a passport document.
- Create 4 prompt variables, each of type cldfs__QueryDocumentPrompt.
- The number of prompt variables depends on the queries you want to execute.
2 - Assign Queries
For each prompt variable:
- Assign a unique ID (used to map the result to its query).
- Assign the Query (a plain text prompt specifying the information to retrieve). You can directly pass a string as the query (e.g., "Extract the passport holder's name."). Alternatively, you can pass the query dynamically through a variable, formula etc. allowing to incorporate complex use cases.
3 - Create a Collection
After defining and assigning all prompt variables:
- Create a collection variable of type cldfs__QueryDocumentPrompt.

- Add all the these individual prompt variables to the collection

- This collection will serve as the Prompts input parameter for the action.
- 
The action outputs Prompts ( an Apex-Defined collection variable of Apex Class cldfs__QueryDocumentPrompt ). This collection contains all the Prompts that were input, along with their corresponding results.
Steps to Filter Results from Outputs
1 - Loop Through Outputs
Use a Loop element in your flow to iterate over the Prompts collection output by the action.
Considering the same previous example. The Loop shall look something like this:
2 - Add a Decision to check the "ID" of Current Prompt
Insert a Decision element inside the loop to filter prompts based on their ID (assigned during input configuration). This helps identify which Prompt Result corresponds to which Prompt Query.
3 - Assign the corresponding Result as needed
After filtering the desired prompt using the Decision, access the Result field of that prompt variable. Assign the result to the appropriate field or use it as needed in the flow.
With reference to the previous example, assign the Passport Number Result to the Record Field.
These steps ensure you can efficiently extract and utilize query results from the output Prompts collection.