Help Center Document Generation Trigger from a Salesforce Flow

How to Trigger Document Generation from a Salesforce Flow with Dochly

Updated June 2026 10 min read Document Generation
Flow-triggered generation is the most powerful way to automate document creation in Salesforce — documents generate automatically based on any record event without any user action. Dochly exposes a native Flow action that can be used in any Flow type: record-triggered, screen, scheduled, or autolaunched. This guide covers how to set up each Flow type, how to configure the Dochly action correctly, and the common use cases that benefit most from automation.

Which Flow type to use

Choose the Flow type based on when you want generation to trigger. Each type suits different automation patterns.

Screen Flow

Triggered manually by a user — but can include logic, data collection, and decisions before generating. Use for: guided document generation wizards, letting users choose between multiple templates with custom options.

Scheduled Flow

Runs on a time-based schedule — daily, weekly, monthly. Use for: monthly invoice runs, weekly renewal notice batches, quarterly compliance docs. Works on a record collection rather than a single record.

Autolaunched Flow

Called from Apex, another Flow, or a Process Builder. Use for: complex multi-step automation where document generation is one step in a larger workflow orchestrated from code or a parent Flow.


How the Dochly action appears in Flow Builder

Once Dochly is installed and connected, the Generate Document action appears automatically in the Flow Builder action picker. No additional configuration is needed to make it available.

To find it in a Flow: Add Element → Action → search for "Dochly" or "Generate Document". The action appears under the Action category with the label Dochly: Generate Document.

If the Dochly action doesn't appear in the Flow Builder action picker, confirm Dochly is installed (Setup → Installed Packages) and the Dochly connection status is green (Dochly → Settings → Connection Status). The action only becomes available after a successful Dochly connection setup.


Record-Triggered Flow — step-by-step

This is the most common Flow type for document automation. The example below generates a proposal PDF automatically when an Opportunity's stage changes to "Proposal Sent".

1

Create a new Flow

Go to Salesforce Setup → Flows → New Flow. Select Record-Triggered Flow. Click Create.

2

Configure the trigger

In the Start element, configure the trigger settings:

  • Object: Opportunity (or whichever object your template is based on)
  • Trigger: A record is updated
  • When to run the Flow's actions: Only when a record is updated to meet the condition requirements
  • Run asynchronously: Enabled — runs after the record saves, avoiding any impact on the save transaction
3

Add a condition on the trigger

In the Start element, add an Entry Condition to ensure the Flow only runs when the specific change you're targeting occurs:

  • Field: StageName
  • Operator: Equals
  • Value: Proposal Sent

Also add a Prior Value condition to ensure the Flow only runs when the stage changes to "Proposal Sent" — not when any other field on a Proposal Sent Opportunity is updated:

  • Condition: StageName Prior Value Does Not Equal "Proposal Sent"
4

Add the Dochly Generate Document action

Click the + after the Start element to add an element. Select Action. In the action picker, search for "Dochly" and select Dochly: Generate Document.

Give the action element a clear label — e.g. "Generate Proposal PDF".

5

Configure the action inputs

The action requires two inputs and supports several optional ones. See the Field Reference below for full details. For this example:

Dochly: Generate Document — action inputs
Record ID Required
{!$Record.Id}

The ID of the triggering record. For record-triggered Flows, always use {!$Record.Id}.

Template ID Required
a0X000000XXXXXXX

The Salesforce ID of the Active Dochly template to use. Find it in Dochly → Templates → [Template] → copy the ID from the record URL.

Output Format Optional
PDF

PDF (default), DOCX, or XLSX. Leave blank to use the template's default output format.

Send Email Optional
false

Set to true to automatically email the generated document. Requires Email Recipient to also be set.

Email Recipient Optional
{!$Record.Contact.Email}

Email address to send the document to. Use a merge field to pull from the record dynamically.

6

Add a fault path

Always add a fault path to the Generate Document action. Without one, if the action fails (e.g. the template is set to Draft accidentally), the Flow fails silently and you won't know generation didn't happen.

Click the Generate Document action element → click Add Fault Path. Connect the fault path to an action that makes the failure visible — create a Task on the record, send an email to the admin, or update a field on the record.

A simple fault path: create a Salesforce Task on the Opportunity with Subject = "Document generation failed — check Dochly logs". This surfaces the failure directly on the record.

7

Save, activate, and test the Flow

Save the Flow with a clear name — e.g. "Opportunity: Generate Proposal on Stage Change". Click Activate.

To test: open a test Opportunity and change its stage to "Proposal Sent". Within a few seconds, the document should appear in the Opportunity's Files related list. Check the generation log in the Dochly Activity panel on the record if the file doesn't appear.

Test in a sandbox before activating in production. An incorrectly conditioned Flow can trigger document generation for every Opportunity updated in the org — potentially generating thousands of documents.


Flow action field reference

Complete reference for all inputs and outputs of the Dochly: Generate Document Flow action:

All input fields
Record ID Required

The Salesforce Record ID of the record to generate from. For record-triggered Flows: {!$Record.Id}. For screen Flows: pass the record ID from the triggering record or a user selection.

Template ID Required

The Salesforce Record ID of the Active Dochly template. Find it in Dochly → Templates → [Template Name] → copy the 18-character Salesforce ID from the browser URL. Store it as a Flow variable if reusing across multiple elements.

Output Format Optional

Accepted values: PDF, DOCX, XLSX. Defaults to the template's configured output format if left blank.

Storage Destination Optional

Overrides the Dochly Settings storage destination for this specific generation. Leave blank to use the org-level default (recommended for most Flows).

Send Email Optional

Boolean — true or false. When true, the generated document is emailed to the address in Email Recipient immediately after generation.

Email Recipient Optional

Email address string. Required if Send Email = true. Use a Flow formula or merge field to pull dynamically: {!$Record.Contact.Email} or a formula resource that resolves the correct email based on record conditions.

File Name Optional

Custom file name for the generated document. Supports merge values from Flow variables. Leave blank to use the template's default naming convention.

Output variables
Generated File ID

The Salesforce ContentDocument ID of the generated file. Store this in a Flow variable to reference the file in subsequent actions — e.g. to send it via email, update a field on the record with the file ID, or add it to a Chatter post.

Generation Status

Returns Success or Failed. Use this output in a Decision element to branch your Flow based on whether generation succeeded — e.g. update a field to "Document Sent" on success, or create a Task on failure.


Screen Flow

A Screen Flow lets users trigger document generation through a guided wizard — collecting inputs, making choices, and then generating. This is useful when users need to select between multiple templates or confirm details before generating.

When to use Screen Flow

When users need to make a choice before generating — select a template from a list, enter a custom message, choose the output format, or confirm recipient details. Screen Flows give users control over generation options without exposing the full Dochly interface.

Key setup difference

Screen Flows are launched from a button or Quick Action on the record page. The Record ID is passed in as an input variable from the launching context. Add a Screen element before the Generate Document action to collect user inputs, then pass those inputs to the action.

To add a Screen Flow to a record page: create the Flow, then in Salesforce Setup → Object Manager → [Object] → Buttons, Links, and Actions → New Action → Action Type = Flow. Select your Flow, give it a label (e.g. "Generate Custom Proposal"), and add it to the page layout as you would any other action button.


Scheduled Flow

Scheduled Flows run automatically on a time-based schedule — processing collections of records rather than individual triggered records. Use them for recurring document generation workflows like monthly invoices or weekly renewal notices.

How scheduled Flows work

A Scheduled Flow runs at a set time (daily, weekly, monthly) and iterates over a collection of records that match a SOQL filter. For each record in the collection, the Flow runs the Generate Document action.

When to use batch jobs instead

For large record sets (500+), Dochly's native Batch Document Jobs are better than a Scheduled Flow — they handle parallelism, error logging, and retry logic more efficiently than a Flow loop. See Run a batch document job.


Common automation use cases

Record-Triggered · Opportunity updated

Generate and email a proposal when stage changes to "Proposal Sent"

Trigger: Opportunity StageName changes to "Proposal Sent". Action: Generate proposal PDF, email to primary Contact. Result: rep changes the stage and the proposal arrives in the customer's inbox automatically — zero manual steps.

Record-Triggered · Opportunity updated

Generate an invoice when an Opportunity is Closed Won

Trigger: Opportunity StageName changes to "Closed Won". Action: Generate invoice PDF, attach to record, update Invoice_Status__c to "Sent". Result: every closed deal automatically gets an invoice stored on the record and ready to send.

Record-Triggered · Account created

Generate and send a welcome letter when a new Account is created with Type = Customer

Trigger: Account record created AND Type = "Customer". Action: Generate welcome letter, email to Account's primary Contact. Result: every new customer receives a branded welcome letter without any sales rep action.

Record-Triggered · Contract updated

Generate a renewal notice 60 days before Contract end date

Trigger: Contract Days_Until_Expiry__c (formula field) changes to 60. Action: Generate renewal notice PDF, attach to Contract record. Result: renewal notices are created exactly 60 days before expiry without anyone monitoring contract dates.

Screen Flow · User-triggered

Guided document wizard — user selects template and recipient

Screen 1: User selects which document type to generate (Proposal / Contract / Invoice). Screen 2: User confirms recipient email. Action: Generate selected template and email to confirmed recipient. Result: users get guided generation without needing to understand the Dochly interface.


Best practices

Always add a fault path

Every Dochly action in a Flow should have a fault path that surfaces failures visibly — create a Task, update a field, or send an admin email. Silent failures are the hardest generation issues to diagnose.

Use Prior Value conditions

For stage-change triggers, always add a Prior Value condition so the Flow only fires when the field changes to the target value — not when any other field on the record is updated while it's already at that stage.

Run asynchronously

For record-triggered Flows, set "Run asynchronously" in the trigger. This decouples generation from the save transaction — generation happens after the record saves, preventing any impact on save performance.

Test in sandbox first

Always activate and test in a sandbox before production. Test from a record that meets the trigger conditions and verify the document generates and stores correctly before exposing it to live users.

Use the Generation Status output

Capture the Generation Status output variable and use a Decision element to branch on success vs failure. This allows the Flow to take different actions based on whether generation succeeded.

Store Template ID as a constant

Store the Dochly Template ID as a Flow Constant (not hardcoded in the action input). This makes it easy to swap to a different template version without editing multiple action elements across the Flow.


Frequently asked questions

The Dochly Flow action only becomes available after the package is installed and connected. Check Setup → Installed Packages — Dochly should show Status = Installed. Then check Dochly → Settings → Connection Status — if any indicator shows red, re-run the Setup Wizard to re-establish the connection. After fixing the connection, the action should appear in Flow Builder within a few minutes.
Yes. Use a Decision element before the Generate Document action to branch based on a field value (e.g. Opportunity Type), then pass a different Template ID constant to the action in each branch. This allows the same Flow to select different templates based on record conditions — e.g. Enterprise Proposal template vs SMB Proposal template based on Account size.
Check three things in this order: (1) confirm the Template ID in the action is pointing to an Active template — if the template was set to Draft or Inactive after the Flow was built, generation will fail silently; (2) check Setup → Paused and Failed Flow Interviews for any Flow errors; (3) check the Dochly Activity Log on the record — it shows whether generation was attempted and what error occurred. Add a fault path to the action to surface errors visibly going forward.
Yes. Add multiple Generate Document action elements to the same Flow — one per document type. For example, when an Opportunity closes, you could generate both an invoice and a signed agreement by adding two separate Generate Document actions in sequence, each with a different Template ID. Each action stores its output document on the record independently.

Document generation now triggers automatically based on any Salesforce record event. Next in this series: How to schedule automatic document generation in Salesforce with Dochly — set recurring generation on daily, weekly, and monthly schedules.

Dochly
Salesforce AppExchange — UTECH HUB Install Dochly on AppExchange

Rated 5 stars · Native Salesforce app · Free to install