For the complete documentation index, see llms.txt. This page is also available as Markdown.

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).

Last updated

Was this helpful?