# Query Document/Dataset (Batch)

Ask several questions of a processed document or a dataset in one call from Apex, through the Query Document/Dataset (Batch) action class.

> Kind: Apex method · Updated: 2026-10-05

## Signature

```apex
global static List<QueryDocumentBatch.FlowOutput> execute(
  List<QueryDocumentBatch.FlowInput> inputs
)
```

### Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| inputs | List&lt;QueryDocumentBatch.FlowInput&gt; | required | One entry per document or dataset to query, each with its list of prompts. Every prompt in every entry is sent in one request. See the field breakdown below. |

### FlowInput

### FlowInput
| Parameter | Type | Required | Description |
|---|---|---|---|
| processedDocumentId | String | optional | Id of the processed document to query. Set this or datasetId. |
| datasetId | String | optional | Id of the dataset to query. Set this or processedDocumentId. |
| agent | String | optional | Optional agent to run the queries with. |
| prompts | List&lt;<a href="#/apex-type-query-document-prompt">QueryDocumentPrompt</a>&gt; | required | The questions to ask, one per prompt. |

### FlowOutput

### FlowOutput
| Parameter | Type | Required | Description |
|---|---|---|---|
| prompts | List&lt;<a href="#/apex-type-query-document-prompt">QueryDocumentPrompt</a>&gt; | optional | The prompts from the matching input, each with result set to the answer. |

## Return Type

List<QueryDocumentBatch.FlowOutput&gt;. One output per input, in the same order. Each output holds the same prompts you passed in, with result filled in with the answer.

## Example

```apex
cldfs.QueryDocumentPrompt total = new cldfs.QueryDocumentPrompt();
total.id = 'total';
total.query = 'What is the invoice total?';

cldfs.QueryDocumentPrompt dueDate = new cldfs.QueryDocumentPrompt();
dueDate.id = 'dueDate';
dueDate.query = 'When is the payment due?';

cldfs.QueryDocumentBatch.FlowInput input = new cldfs.QueryDocumentBatch.FlowInput();
input.processedDocumentId = '68f1c2a9e4b0d35a7c9e1f21';
input.prompts = new List<cldfs.QueryDocumentPrompt>{ total, dueDate };

List<cldfs.QueryDocumentBatch.FlowOutput> outputs = cldfs.QueryDocumentBatch.execute(
  new List<cldfs.QueryDocumentBatch.FlowInput>{ input }
);
for (cldfs.QueryDocumentPrompt prompt : outputs[0].prompts) {
  System.debug(prompt.id + ': ' + prompt.result);
}
```

> **Synchronous** — The answers come back in the same call, so this method makes a callout and the usual Apex callout limits apply: call it before any DML in the transaction, or from an asynchronous context. To ask one question, or to build the queries yourself, use Query Document.
