---
isPublished: true
knowledgeIndex: false
hidden: true
noindex: true
template: "page.peb"
title: "Generate and Send Document Flow Reference"
description: "Generate a document from a template and optionally send it as an email attachment."
contentType: "reference"
audience: "admin,developer"
---

# Generate and Send Document

Generate a document from a template and optionally send it as an email attachment.
The namespaced Apex action name is `rooms__DocumentGenerateAction`.

## Transaction summary

| Effect | Behavior |
| --- | --- |
| API callout | Yes. Synchronous generation makes the callout in the action step; Run Async moves generation to later processing. |
| Record writes | Creates the generated File or Attachment through the requested generation. Validation or processing errors can create DialogueOne Event records. Email can save an activity when enabled. |
| Platform event | Successful File-template merging can publish a document-merge event. |
| Background work | Run Async defaults to `true` and queues generation. No completion outputs are returned. |
| Email | Sends a native Salesforce email when Email Send Enabled is `true`. |

This action returns no generated-document ID or Success output. It can publish document-generation events. Use [Generate Document](/content/build/flows/CreateDocumentAction.md) when the Flow needs a confirmed File or Attachment output. Use [Generate XP Document](/content/build/flows/GenerateXPDocumentAction.md) before Create Experience.

## Inputs

Required describes the Flow input setting. Additional configuration rules can still require a value.

| API name | Flow label | Required | Default or guidance |
| --- | --- | --- | --- |
| `masterRecordId` | Record ID | Yes | The Salesforce source record to merge. |
| `contentDocumentID` | Template ID | No | Supply the template ContentVersion or ContentDocument ID. This value is required for generation. |
| `roomItemID` | Room Item ID | No | Exposed input. It is not used to select the generated document in this action. |
| `attachmentIDFieldName` | Attachment ID Field Name | No | Exposed input. This action does not write the resulting attachment ID into that field. |
| `parentId` | Parent ID (default=RecordId) | No | Defaults to Record ID when blank. |
| `fileName` | File Name | No | Defaults to `GeneratedDocument.PDF`; blank uses `GeneratedDocument.pdf`. |
| `fileDescription` | File Description | No | Defaults to an empty value. |
| `fileFormat` | File Format (PDF or WORD) | No | Defaults to `PDF`. Valid values: `PDF`, `WORD`. |
| `contentType` | Content MIME Type (Inherited from file format) | No | Defaults to `application/pdf`. Set the matching MIME type for the requested format. |
| `attachAs` | Attach As (Attachment or File) | No | Defaults to `Attachment`. Use `File` for a Salesforce File. |
| `attachAsNewVersion` | Attach As New Version | No | Defaults to `false`. Requests a new File version when applicable. |
| `emailSend` | Email Send Enabled (default=false) | No | Defaults to `false`. Set `true` to send the generated attachment. |
| `emailToId` | Email To ID | No | Recipient identity. Use with an email template when personalization needs it. |
| `emailToAddress` | Email To Address | No | Required with Email To Name when Email To ID is blank. |
| `emailToName` | Email To Name | No | Required with Email To Address when Email To ID is blank. |
| `emailFromAddress` | Email From Address | No | Sender/reply-to address. A matching permitted organization-wide address can be used. |
| `emailFromName` | Email From Name | No | Sender display name. |
| `ccEmailAddresses` | CC Email Addresses | No | Optional comma-separated CC addresses. |
| `bccEmailAddresses` | BCC Email Addresses | No | Optional comma-separated BCC addresses. |
| `emailTemplateName` | Email Template Name | No | Email template developer name. Otherwise supply Email Subject and Email Body. |
| `targetObjectId` | Email Template Target Object Id | No | Legacy email-template target input. Prefer Email To ID for the recipient. |
| `emailSubject` | Email Subject | No | Required without Email Template Name when email is enabled. |
| `emailBody` | Email Body | No | Required without Email Template Name when email is enabled. |
| `saveAsActivity` | Email Save As Activity | No | Defaults to `false`. Enables native email activity saving when supported. |
| `runAsync` | Run Async (@future method context) | No | Defaults to `true`. Set `false` only when the Flow requires synchronous generation. |

## Outputs

This action has no Flow outputs. Connect a Fault path for exceptions that reach the Flow. Confirm the requested business result separately.

## Configure the Flow

1. Set the source record, template and document format.
2. Choose the attachment method and parent.
3. Choose synchronous or asynchronous processing.
4. If email is enabled, configure a valid recipient and either a template or subject and body.
5. Connect a Fault path, then monitor the generated File, job and DialogueOne Events.

Confirm the Flow user's Apex action access and access to the records or Files used by this operation. Review the configured Salesforce API connection user's access when the action makes an API request. For native Salesforce email, also confirm email access, permitted sender configuration and any required activity access.

## Troubleshooting

**The Flow continues but no document is available.** The default mode queues processing and provides no completion outputs.

**Email fails after generation.** Check the existing generated document before repeating the action. Repeating the action can generate another document.

**You have uncommitted work pending.** Synchronous generation makes a callout. Validation and error Events can also write records. Review transaction settings and reported errors.

See the [Flow action catalog](/content/build/flows/index.md) for related actions and transaction guidance. Confirm that the action and input fields are available in the installed package.
