> 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/developer-hub/document-workflows/software-development-kit/batch-sdk/sdk-how-to-guide-batching-and-combining-documents.md).

# SDK How-to Guide: Batching and Combining Documents

This guide addresses the need to bulk-process documents (e.g., printing invoices for all Accounts) and deliver them as a single packet.

**Introduction**

The `generateDocsInBatch` method allows you to process a list of records. To merge them, we utilize the `CombinedDocumentHandler` class.

**Step 1: Prepare Your Data**

Identify the list of records you want to process. For this example, we will query two accounts.

`ApexList<Account> accounts = [SELECT Id FROM Account LIMIT 2]; List<Id> accountIds = new List<Id>(); for(Account a : accounts){ accountIds.add(a.Id); }`

**Step 2: Configure the Batch Action**

To combine the documents, you must instantiate the `CombinedDocumentHandler` within a list of `BatchAction`.

`Apex// Create the batch action list List<SDOC.BatchAction> actions = new List<SDOC.BatchAction>(); // Add the handler that merges files into one PDF actions.add(new SDOC.CombinedDocumentHandler());`

**Step 3: Execute the Batch**

Pass your record IDs, template IDs, batch size, and actions to the SDK.

`ApexId templateId = '00Xxxxxxxxxxxxx'; // Ensure this is a PDF template Set<Id> templateIds = new Set<Id>{templateId}; // Execute Batch // Parameters: Record IDs, Template IDs, Batch Size (5), Actions String jobId = SDOC.DocumentSDK.generateDocsInBatch( accountIds, templateIds, 5, actions ); System.debug('Batch Job ID: ' + jobId);`

**Step 4: Verification**

Monitor the Apex Jobs page in Salesforce Setup. Once the job completes, the combined PDF will be attached to the first record in the batch (or handled according to your specific configuration).


---

# 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/developer-hub/document-workflows/software-development-kit/batch-sdk/sdk-how-to-guide-batching-and-combining-documents.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.
