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