# SDK Reference

The `SDOC.DocumentSDK` class provides static methods for generating and managing documents.

#### `generateDocument`

Generates a single document synchronously.

* **Signature:**

{% code title="Signature" %}

```apex
generateDocument(Id templateId, Id recordId, GenerationOptions options)
```

{% endcode %}

* **Parameters:**
  * `templateId` (Id): The ID of the S-Docs template.
  * `recordId` (Id): The ID of the base Salesforce record.
  * `options` (SDOC.GenerationOptions): Optional. Specifies email settings, user inputs, or file save behaviors.
* **Returns:**
  * `String` (JSON): Contains `contentDocumentId`, `attachmentName`, `createdDate`, etc.
* **Supported Contexts:**

  * Apex Invocable (Flow), Queueable, Batch, @future, Visualforce Controllers, Aura/LWC Controllers.

  <div data-gb-custom-block data-tag="hint" data-style="warning" class="hint hint-warning"><p>NOT supported in Apex Triggers (will throw Exception).</p></div>
* **Limitations:**
  * Only 1 invocation allowed per Apex transaction (to avoid limits).
  * Supports PDF and PDF-UPLOAD formats only.

#### `generateEmail`

Generates the HTML body of an email using an S-Docs template.

* **Signature:**

{% code title="Signature" %}

```apex
generateEmail(Id templateId, Id recordId)
```

{% endcode %}

* **Returns:**
  * `String`: The HTML content of the email body.
* **Usage:**
  * Commonly used to populate a `Messaging.SingleEmailMessage` object in Apex for richer content than standard Salesforce templates allow.

#### `generateDocsInBatch`

Initiates an asynchronous batch job to generate documents for multiple records.

* **Signature:**

{% code title="Signature" %}

```apex
generateDocsInBatch(List<Id> recordIds, Set<Id> templateIds, Integer batchSize, List<SDOC.BatchAction> batchActions)
```

{% endcode %}

* **Parameters:**
  * `recordIds`: List of base record IDs.
  * `templateIds`: Set of template IDs to generate for each record.
  * `batchSize`: Integer (Default 5).
  * `batchActions`: List of actions, such as `new SDOC.CombinedDocumentHandler()`.
* **Returns:**
  * `Id`: The AsyncApexJob ID.


---

# 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/references/software-development-kit-sdk/sdk-reference.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.
