---
isPublished: true
knowledgeIndex: false
hidden: true
noindex: true
template: "page.peb"
title: "Generate Document Flow Action"
description: "Inputs, outputs, callouts, record effects and transaction guidance for the DialogueOne Generate Document Flow action."
contentType: "reference"
audience: "admin,developer"
seoTitle: "Generate Document Flow Action Reference"
seoDescription: "Configure Generate Document in Salesforce Flow and troubleshoot callout, template, output and transaction errors."
---

# Generate Document

Use **Generate Document** to merge a Salesforce record with a document template and save the result.
The namespaced Apex action name is `rooms__CreateDocumentAction`.

Use [Generate XP Document](/content/build/flows/GenerateXPDocumentAction.md) when the next step is
[Create Experience](/content/build/flows/CreateExperienceAction.md).
Generate Document does not return the generated XP Content ID that Create Experience requires.

## Transaction summary

| Effect | Behavior |
| --- | --- |
| API callout | Yes. The action waits for the API response. |
| Record writes | Requests a generated Salesforce File or Attachment and its record link. For File-template generation, a merge-field error can also create an DialogueOne Event record in the calling Flow transaction. |
| Platform event | When Data Definition Key is blank, successful File-template generation publishes a document-merge event. The PDF path selected by a Data Definition Key does not publish that event. |
| Email | The action does not send email. |
| Background work | This Flow action does not support its Run Asynchronous input set to `true`. |

Earlier record writes or other pending work can prevent the callout.
Do not assume that a later Flow fault removes a document that was already generated.

## Inputs

**Required** below describes the Flow input setting. The template-selection rules also apply.

| API name | Flow label | Required | Default or guidance |
| --- | --- | --- | --- |
| `recordId` | Record ID (Record to be merged) | Yes | The Salesforce source record. |
| `documentTemplateId` | Document Template ID (ContentVersion template used in merge) | No | A template `ContentVersion` ID (`068`) or `ContentDocument` ID (`069`). Required unless a Template Content selector supplies it. |
| `dataContextId` | Data Definition Key | No | A Data Context Definition key, not its Salesforce record ID. Use only with PDF and an exact template `ContentVersion` ID (`068`). |
| `templateContentId` | Template Content ID | No | The published template's `rooms__Content__c` ID. Supplies the template File and related settings. |
| `templateDeveloperName` | Template Developer Name | No | An alternative to Template Content ID. Use the published template's developer name. |
| `xpTemplateId` | XP Template ID | No | Supplied when Template Content is selected. Leave blank for that selection. |
| `xpTemplateRevisionId` | XP Template Revision ID | No | Supplied when Template Content is selected. Leave blank for that selection. |
| `parentId` | Parent ID (default=RecordId) | No | Defaults to `recordId`. Select the record that must receive the document. |
| `fileName` | File Name | No | Initial value: `GeneratedDocument.PDF`. With Template Content selection, a blank or default name uses the published template File title. |
| `fileDescription` | File Description | No | Defaults to an empty value. |
| `fileFormat` | File Format (PDF or WORD) | No | Defaults to `PDF`. Valid values: `PDF`, `WORD`. Template Content selection uses PDF. |
| `contentType` | Content MIME Type (Inherited from file format) | No | Set from File Format: PDF or Word document MIME type. |
| `attachAs` | Attach As (Attachment or File) | No | Defaults to `Attachment`. Valid values: `Attachment`, `File`. Select `File` for Salesforce Files. |
| `attachAsNewVersion` | Attach As New Version | No | Defaults to `false`. For Files, requests a new version of an existing File. |
| `runAsync` | Run Asynchronous (@future method) | No | Defaults to `false`. A value of `true` returns an unsupported-mode error. |

Choose one template method:

1. Supply a template File ID in `documentTemplateId`.
2. Supply `templateContentId` or `templateDeveloperName` for a published Template Content record.

Template Content ID takes precedence over Template Developer Name.
Template Content selection replaces the template File and related template settings.
For Template Content selection, the template must be active, current and published, with a valid Data Context Definition.

## Outputs

| API name | Flow label | Meaning |
| --- | --- | --- |
| `success` | Success | `true` confirms generation and a valid document reference. Test this value before continuing. |
| `message` | Message | Result details or an error. |
| `recordID` | Record ID | The source record. |
| `parentID` | Parent ID | The document attachment parent. |
| `documentTemplateID` | Document Template ID | The selected template File reference. |
| `attachmentID` | Attachment ID | The generated File or Attachment reference when Success is `true`. On failure, this value can contain the source Record ID. |
| `runAsync` | Run Asynchronous (@future method) | The requested execution setting. This value does not confirm that background work started. |
| `fileName` | File Name | The selected output name. |
| `fileDescription` | File Description | The requested description. |
| `fileFormat` | File Format | The selected output format. |
| `contentType` | Content MIME Type | The output MIME type. |
| `attachAs` | Attach As | The selected attachment method. |
| `attachAsNewVersion` | Attach As New Version | The requested File-version setting. |

Never treat Attachment ID alone as proof of success.
Save the Message output and connect the action's Fault path.

## Configure the Flow

1. Confirm the source record and published template.
2. Add **Generate Document** from the Apex action list.
3. Set Record ID and one template selector. Set Run Asynchronous to `false`.
4. Select the output format, attachment method and parent.
5. Review the action's Advanced transaction setting for the Flow type.
6. Store Success, Message and Attachment ID.
7. Continue only when Success equals `true`. Handle the false result and Fault path separately.

```mermaid
flowchart TD
    A[Select source record and template] --> B[Generate Document callout]
    B --> C{Success is true?}
    C -- Yes --> D[Use the confirmed File or Attachment]
    C -- No --> E[Show Message and inspect existing results]
    B -- Fault --> E
```

Confirm the Flow user's action access and the required source-record, template and File access.
Review the configured Salesforce API connection user's access.
See [XP access and permissions](/content/support/xp-permissions.md).

## Troubleshooting

**You have uncommitted work pending.** This action makes an API callout.
Check record writes and other pending work before the action in the same transaction.
Review [transaction settings and debugger limits](/content/build/flows/index.md#resolve-uncommitted-work-pending).
If there is no earlier Flow record-write step, inspect DialogueOne Events for a merge-field error.
File-template processing can record that error before its callout.
Correct the reported merge-field error before retrying. Moving the Flow action to another transaction alone might not remove this cause.

**Asynchronous generation is not supported.** Set Run Asynchronous to `false`.
For record-triggered automation, review an asynchronous or scheduled path and its transaction settings.
Changing this input to `true` does not create that Flow path.

**Template selection fails.** For Template Content selection, confirm that the template is active, current and published.
For Data Definition Key, supply a key and an exact `ContentVersion` ID. Use PDF.
For Word output, use the template File selection method.

**The response is unsuccessful or uncertain.** Read Message and inspect related Files, Attachments and DialogueOne Events.
A timeout can occur after generation. Confirm whether the document exists before generating it again.

**Create Experience rejects the output.** Attachment ID is not a generated XP Content ID.
Use [Generate XP Document](/content/build/flows/GenerateXPDocumentAction.md) and pass its
`contentRecordId` output to Create Experience.

See the [Flow action index](/content/build/flows/index.md) for action selection and the shared example.
