> 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/combine-generated-documents-with-flow.md).

# Combine Generated Documents with Flow

Use this guide when you want a **Flow** to combine existing generated **S-Docs** into one file.

Use this pattern when the documents already exist and you want one final file for delivery, review, or storage.

{% hint style="info" %}
This action combines documents that were already generated in S-Docs.

Use supported source formats such as **PDF** and **PDF-Upload**.
{% endhint %}

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

Add the **SDoc** IDs to a text collection 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
* Generated **SDoc** records to combine
* Access to the target **SDoc** records
* Access to any record or library where the combined file should be linked
* One **Text** collection variable for **SDoc** record IDs
* An optional second **Text** collection variable for link record IDs

<figure><img src="/files/KoiUauhVyzPCt5fZyeAX" alt="Flow outline for combining generated S-Docs" width="339"><figcaption></figcaption></figure>

### Step-by-step tutorial

#### Step 1: Create the SDoc ID text collection

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

Create a **Variable** resource.

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

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

Use this collection to store the generated **SDoc** record IDs.

#### Step 2: Get the SDoc records in the order you want

Add a **Get Records** element for **SDoc** records.

Filter for the documents you want to combine.

Choose **Get All Records**.

Sort the records in the exact order you want in the final file.

The combined output follows the order of the IDs you pass into the action.

#### Step 3: Loop through the records and add each ID to the collection

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

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

Append each current record `Id` to the **Text** collection variable.

Use the loop only to build the collection.

Do not run the combine action inside the loop.

#### Step 4: Add the Combine Documents action

Add an **Action** element after the loop.

Choose the S-Docs combine documents action.

Enter a **Label** and **API Name**.

Use the action that accepts a text collection of generated **SDoc** record IDs.

<figure><img src="/files/xXoeCZGaaeXr3I6pFRVO" alt="Combine Documents action selected in Flow Builder"><figcaption></figcaption></figure>

#### Step 5: Map the required and optional values

Map **S-Doc IDs** to the text collection of generated **SDoc** record IDs.

Map **Link Record IDs** only when you want to link the combined file to records or libraries.

Map **Combined File Name** only when you want to override the default file name.

If **Combined File Name** is blank, S-Docs uses `Combined Document`.

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

Save the **Flow**.

Activate it.

Then run a test and confirm the Flow:

* combines the expected documents
* keeps the expected document order
* links the combined file where you expect
* creates the file in **Salesforce Files** when no link target is passed

### Troubleshooting and common errors

<details>

<summary><strong>No combined file is created</strong></summary>

* **Symptom:** The **Flow** finishes, but no combined file is created.
* **Cause:** The **S-Doc IDs** collection is blank, or it contains IDs that are not valid generated **SDoc** records.
* **Fix:** Check the **Get Records**, **Loop**, and **Assignment** elements. Confirm each `Id` is added to the correct **Text** collection before the action runs.

</details>

<details>

<summary><strong>The documents are combined in the wrong order</strong></summary>

* **Symptom:** The combined file includes the right documents, but the order is wrong.
* **Cause:** The **Get Records** sort order does not match the intended output order.
* **Fix:** Update the **Get Records** sort order before the loop. Then test again.

</details>

<details>

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

* **Symptom:** The action succeeds, but you do not see the output where you expected.
* **Cause:** No link target was passed into the action.
* **Fix:** Check **Salesforce Files** first. That is the default location when no record or library is provided.

</details>

<details>

<summary><strong>The Flow faults when the action runs</strong></summary>

* **Symptom:** The **Flow** errors when it reaches the combine action.
* **Cause:** The running user cannot access one or more **SDoc** records, or cannot link the file to the target record or library.
* **Fix:** Confirm object access, record access, and file access for the running user. If needed, add a **Fault** path so the Flow surfaces the exact error during testing.

</details>

### Advanced configurations and reference

* Field-level action details: [Flow Reference](/developer-hub/document-workflows/flow-reference.md#combine-documents)

#### Required action input

* **S-Doc IDs** — Required. Pass a **Text** collection of generated **SDoc** record IDs.

#### Optional action inputs

* **Link Record IDs** — Optional. Pass a **Text** collection of record IDs or library IDs where the combined file should be linked.
* **Combined File Name** — Optional. Pass a **Text** value for the output file name.

#### Output behavior

* The action creates one combined file from the **SDoc** records you pass in.
* The action follows the order of the IDs in the collection.
* If you pass link targets, S-Docs links the file to those records or libraries.
* If you do not pass link targets, 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/combine-generated-documents-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.
