# How To: Generate Documents in Batch

<figure><img src="/files/nomu2g42ShBSn0bCwXiq" alt=""><figcaption></figcaption></figure>

### Understanding the Overall Schema

Outlined above is the generalized process from start to finish users will take to generate documents in Batch.

The process goes as follows:

1. **Collect Data** that will be used for document generation (S-Docs Template(s) + Object Record(s))
2. **Loop** the collected Records and add their IDs to **Collections**
3. **Configure the Generate Action** and **Generate in Batch**

Generating document in batch will generate the product of all combinations of Object Records and Template IDs. In other words the generated documents produced are the set of all ordered pairs (a,b) where a is from A and b is from B.&#x20;

{% hint style="info" %}
Individually generated documents will be tied to the Base Record used during generation by Default. If using the Combine Documents Setting, the Combined Document will live under the Salesforce Files object by Default.&#x20;
{% endhint %}

***

### Phase 1: Gather the Data

<figure><img src="/files/2UZAAYYG9YdjnRMBoTm1" alt="" width="464"><figcaption></figcaption></figure>

In this example we will be finding multiple templates to use for generation.&#x20;

* Set the Filters used for your Search
* Select **All Records** to store all the records that have met this criteria

***

### Phase 2: Loop the Data & Assign to Collections

<figure><img src="/files/R1KpAcYpxzSUAWtjjwpl" alt=""><figcaption></figcaption></figure>

Loop through the collected records, assigning each Record ID to the same collection Variable with **Data Type Text.**&#x20;

***

### Phase 3: Generate Documents in Batch

<figure><img src="/files/h0hVLt6A1uPEh2aPAHOd" alt=""><figcaption></figcaption></figure>

Provide the Collections to the Base Record IDs input and the Template IDs input. Configure settings that best match the use case.&#x20;

{% hint style="info" %}
For large sets of data, leverage the Batch Size setting to limit the number of records processed in a single batch. Limiting Batch Size helps avoid encroaching on Governor Limits.&#x20;
{% endhint %}


---

# Agent Instructions: 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:

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

The question should be specific, self-contained, and written in natural language.
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.
