> For the complete documentation index, see [llms.txt](https://help.sdocs.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.sdocs.com/sdocs/automation-and-document-lifecycle/automate-with-flow/generate-documents-in-batch-with-flow.md).

# Generate Documents in Batch with Flow

Use this guide when you want a **Flow** to generate S-Docs for many records in one run.

Use this pattern when you want to pass a collection of record IDs and a collection of template IDs into one batch action.

{% hint style="info" %}
Batch generation creates one document for each combination of **Base Record IDs** and **Template IDs**.

If you pass `3` records and `2` templates, S-Docs generates `6` documents.
{% endhint %}

{% hint style="warning" %}
Do not place the batch generation action inside a **Loop**.

Add IDs to collections first. Then run the action once outside the loop.
{% endhint %}

#### Start here if you are newer to Flow

New to Flow? Start with [Getting Started: Automate Document Generation](/quick-start/document-generation/getting-started-automate-document-generation.md).

### Prerequisites

* A **Flow** that can run S-Docs actions
* Access to the target base records and S-Docs templates
* A way to collect the target records and templates, usually with **Get Records**
* Two **Text** collection variables
  * one for base record IDs
  * one for template IDs

### Step-by-step tutorial

#### Step 1: Create the text collection variables

In **Flow Builder**, click **Manager** → **New Resource**.

Create a **Variable** resource for base record IDs.

Set **Data Type** to **Text**.

Enable **Allow multiple values (collection)**.

Repeat this step for template IDs.

Use one collection for record IDs.

Use the other collection for template IDs.

<figure><img src="/files/nomu2g42ShBSn0bCwXiq" alt="Flow outline for batch generation"><figcaption></figcaption></figure>

#### Step 2: Get the template records and collect their IDs

Add a **Get Records** element for **S-Docs Template** records.

Filter for the templates you want to use.

Choose **Get All Records**.

Then add a **Loop** element for the returned templates.

Inside the loop, add an **Assignment** element.

Append each template record `Id` to the template ID collection.

<figure><img src="/files/R1KpAcYpxzSUAWtjjwpl" alt="Loop records and assign IDs to a text collection" width="310"><figcaption></figcaption></figure>

#### Step 3: Get the base records and collect their IDs

Add a second **Get Records** element for the records you want to generate against.

Choose **Get All Records**.

Make sure the filter returns only the records you want in the batch.

Add a **Loop** element for the returned records.

Inside the loop, add an **Assignment** element.

Append each base record `Id` to the base record ID collection.

<figure><img src="/files/R1KpAcYpxzSUAWtjjwpl" alt="Assignment element that adds record IDs to a text collection" width="310"><figcaption></figcaption></figure>

#### Step 4: Add the batch generation action

Add an **Action** element after both loops.

Choose the S-Docs batch generation action.

Use the action that accepts **Base Record IDs** and **Template IDs**.

Map these values:

* **Base Record IDs** → the base record ID text collection
* **Template IDs** → the template ID text collection

You can also set these optional values:

* **Batch Size** when you need a smaller processing chunk
* **Combine Documents** when you want one combined output

<figure><img src="/files/h0hVLt6A1uPEh2aPAHOd" alt="Batch generation action with Base Record IDs and Template IDs" width="246"><figcaption></figcaption></figure>

#### Step 5: Save, activate, and test

Save the **Flow**.

Activate it.

Then run a test and confirm the Flow:

* uses the expected records
* uses the expected templates
* generates the expected number of documents
* places combined output in **Salesforce Files** when **Combine Documents** is enabled

<figure><img src="/files/nomu2g42ShBSn0bCwXiq" alt="Completed Flow outline for batch generation"><figcaption></figcaption></figure>

### Troubleshooting and common errors

<details>

<summary><strong>No documents are generated</strong></summary>

* **Symptom:** The **Flow** finishes, but no S-Docs are created.
* **Cause:** One or both text collections are blank.
* **Fix:** Check the **Get Records**, **Loop**, and **Assignment** elements. Confirm each `Id` is added to the correct collection before the action runs.

</details>

<details>

<summary><strong>The document count is higher than expected</strong></summary>

* **Symptom:** The batch creates more documents than you planned.
* **Cause:** S-Docs creates one document for every record and template combination.
* **Fix:** Reduce the number of records, reduce the number of templates, or tighten the **Get Records** filters.

</details>

<details>

<summary><strong>The Flow faults on a larger run</strong></summary>

* **Symptom:** The action fails when the batch gets larger.
* **Cause:** The run is too large for the current transaction or Flow context.
* **Fix:** Lower **Batch Size** or split the run into smaller groups. If needed, connect a **Fault** path so you can surface a clearer error message.

</details>

<details>

<summary><strong>You cannot find the combined output</strong></summary>

* **Symptom:** The batch succeeds, but you do not see the combined file where you expected.
* **Cause:** Combined output is stored in the default location.
* **Fix:** Check **Salesforce Files** first. Combined output is stored there by default.

</details>

### Advanced configurations and reference

* Field-level action details: [Flow Reference](/developer-hub/document-workflows/flow-reference.md#generate-documents-in-batch)
* Individual documents are tied to the base record by default.
* If you enable **Combine Documents**, the combined file is stored in **Salesforce Files** by default.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://help.sdocs.com/sdocs/automation-and-document-lifecycle/automate-with-flow/generate-documents-in-batch-with-flow.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
