How to Trigger Document Generation from a Salesforce Flow with Dochly
Which Flow type to use
Choose the Flow type based on when you want generation to trigger. Each type suits different automation patterns.
Record-Triggered Flow
Triggers automatically when a record is created, updated, or deleted. Use for: generating proposals when a deal reaches a specific stage, creating invoices when an Opportunity closes, generating welcome letters on Account creation.
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".
Create a new Flow
Go to Salesforce Setup → Flows → New Flow. Select Record-Triggered Flow. Click Create.
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
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"
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".
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:
{!$Record.Id}
The ID of the triggering record. For record-triggered Flows, always use {!$Record.Id}.
a0X000000XXXXXXX
The Salesforce ID of the Active Dochly template to use. Find it in Dochly → Templates → [Template] → copy the ID from the record URL.
PDF
PDF (default), DOCX, or XLSX. Leave blank to use the template's default output format.
false
Set to true to automatically email the generated document. Requires Email Recipient to also be set.
{!$Record.Contact.Email}
Email address to send the document to. Use a merge field to pull from the record dynamically.
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.
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:
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.
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.
Accepted values: PDF, DOCX, XLSX. Defaults to the template's configured output format if left blank.
Overrides the Dochly Settings storage destination for this specific generation. Leave blank to use the org-level default (recommended for most Flows).
Boolean — true or false. When true, the generated document is emailed to the address in Email Recipient immediately after generation.
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.
Custom file name for the generated document. Supports merge values from Flow variables. Leave blank to use the template's default naming convention.
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.
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 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.
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.
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.
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
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.
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.
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.
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.
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
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.
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.
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.
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.
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 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
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.
Rated 5 stars · Native Salesforce app · Free to install