# Generate Document (Batch)

Generate multiple documents from Apex in a single batch, optionally sent for signature as one combined DocuSign envelope.

> Kind: Apex method · Updated: 2026-07-13

## Signature

```apex
global static void execute(
  List<GenerateDocumentBatch.FlowInput> inputs
)
```

### Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| inputs | List&lt;GenerateDocumentBatch.FlowInput&gt; | required | One entry per document group. Each FlowInput carries the documents to generate and the optional signing settings for that group. See the field breakdown below. |

### FlowInput

### FlowInput
| Parameter | Type | Required | Description |
|---|---|---|---|
| inputs | List&lt;GenerateDocumentFlowInput&gt; | required | The documents to generate in this group. Each entry describes one document. |
| signingSettings | GenerateDocumentSigningSettings | optional | Combined-envelope signing options for this group. Leave empty for the default behavior (one envelope per document). |

### GenerateDocumentFlowInput

### GenerateDocumentFlowInput
| Parameter | Type | Required | Description |
|---|---|---|---|
| templateId | String | required | Id of the CloudFiles template to render. |
| documentType | String | required | Output document type, for example 'docx' or 'pdf'. |
| recordId | String | optional | Record Id the document is generated for. |
| cloudFilesVariables | List&lt;<a href="#/apex-type-cloudfiles-variable">CloudFilesVariable</a>&gt; | optional | Merge variables for the template, each a key and value. |
| destination | <a href="#/apex-type-resource">Resource</a> | optional | Where the generated document is stored. |
| params | <a href="#/apex-type-docgen-params">DocGenParams</a> | optional | Additional generation parameters such as PDF security and retention settings. |

### GenerateDocumentSigningSettings

### GenerateDocumentSigningSettings
| Parameter | Type | Required | Description |
|---|---|---|---|
| combineDocuments | Boolean | optional | When true, all documents in this group are sent for signature together as one DocuSign envelope. Signers receive a single email and the signed documents are delivered together. |
| emailSubject | String | optional | Subject of the DocuSign envelope email. Defaults to the first document's template signing settings. |
| emailMessage | String | optional | Message body of the DocuSign envelope email. Defaults to the first document's template signing settings. |

## Return Type

void

## Example

```apex
// Build one or more document inputs
cldfs.GenerateDocumentFlowInput docInput = new cldfs.GenerateDocumentFlowInput();
docInput.templateId = '681b4169c697ffdc2aab2731';
docInput.documentType = 'pdf';
docInput.recordId = '003dL00000YsapJQAR';
docInput.destination = new cldfs.Resource(
  '68887db5ef0b3ca7534dbbd5',
  'folder',
  null,
  'cloudfiles',
  'workspace'
);
docInput.params = new cldfs.DocGenParams();

// Optional: send the whole group as one DocuSign envelope
cldfs.GenerateDocumentSigningSettings signingSettings = new cldfs.GenerateDocumentSigningSettings();
signingSettings.combineDocuments = true;
signingSettings.emailSubject = 'Please sign your documents';

cldfs.GenerateDocumentBatch.FlowInput input = new cldfs.GenerateDocumentBatch.FlowInput();
input.inputs = new List<cldfs.GenerateDocumentFlowInput>{ docInput };
input.signingSettings = signingSettings;

cldfs.GenerateDocumentBatch.execute(
  new List<cldfs.GenerateDocumentBatch.FlowInput>{ input }
);
```

> **Combined-envelope signing & Batch Apex support** — Each processed input publishes a Document Generated event; if generation or signing fails, an Error Event is published for that input.Set combineDocuments = true on the signing settings to send every document in the group as a single DocuSign envelope, so signers get one email and sign everything in one session and the signed documents are delivered together. Leave the signing settings empty to keep the default behavior of one envelope per document.The action runs asynchronously and can be invoked from Batch Apex or other asynchronous (future / queueable) contexts.
