Back to the blog

Auto-generate contracts when Opportunity stage changes in Salesforce

Salesforce 7 min read 9 September 2026

The problem

Your reps finish a deal and change Opportunity.StageName to "Contract Sent" (or whatever you use). Someone then downloads data from Salesforce, pastes it into a 60-page Word statement of work, drags in product rows, exports to PDF, emails it, chases signatures for days, and finally uploads the signed file back to the Opportunity. That process kills time and creates versioning errors.

This guide shows a click-based approach for a Salesforce Admin: use a Record-Triggered Flow to generate the document automatically, send it for signature, and have the signed PDF written back to the Opportunity record.

Salesforce document automation: trigger on Opportunity stage

We’ll build a Flow that runs when an Opportunity stage changes. The Flow will:

  • Run after save when StageName equals your target stage (for example, "Contract Sent").
  • Collect related data: opportunity line items, Account billing address, and a custom approver lookup on Opportunity (for example, Approver__c).
  • Invoke the document-generation action to produce a PDF from a Word template and send for e-signature via your Circularo account.
  • Store the signed PDF back to the Opportunity as a Salesforce File.

Why use a Record-Triggered Flow?

Flows run without code, are in the Admin toolbox, and are supported in sandboxes exactly as in production. Savvy DocuGen can be triggered by a field change, so a Flow is the natural click-first approach.

Document generation Salesforce Flow: step-by-step

Here are the steps you’ll configure in Flow Builder.

1) Start — Trigger criteria

Create a Record-Triggered Flow on Opportunity, run After Save, and set the condition:

StageName Equals Contract Sent

Set it to run only when the record is updated and the condition is met. This prevents generation on every save.

2) Get records — pull related data

Add Get Records elements to fetch:

  • OpportunityLineItems where OpportunityId = {!$Record.Id} (for repeating table rows)
  • Account where Id = {!$Record.AccountId} (for billing address and parent lookup fields)
  • Any custom lookup fields you use for signers, e.g. Approver__c, to read signer emails or passwords stored on the Contact or User record.

Savvy DocuGen supports up to five levels of parent lookups and child/grandchild repeating rows, so you can include hierarchical data without building custom serialization logic.

3) Action — call the document generation

Add an Action. Your org will have an authorised connection to Savvy DocuGen (no managed package to install). The Action accepts:

  • Template identifier (the Word template you prepared).
  • Record Id (the Opportunity Id).
  • Options: store output to Salesforce Files, bundle multiple templates if you need cover letters + SOW, and send for signature through your Circularo account.

Set signer fields on the Action. Savvy DocuGen places signature anchors from tags inside your Word template so signatures stay in the right place even if the document repaginates. You can also require an emailed one-time code, and pull a per-signer password from a field on the signer’s record if you want stricter identity control.

4) Decision — handle large documents & storage

If your SOW is large (example: a 60-page SOW with appendices), choose Salesforce Files for storage. Documents up to 40 MB are supported; Notes & Attachments is limited to 25 MB and cannot be raised. Use a Decision element to check expected size (if you compute it) or default to Files for safety.

5) Post-processing — update the Opportunity

After the Action, update the Opportunity with pointers to the generated document: set a custom field like Latest_Signed_Contract__c to the ContentDocumentId or store the Files record in a related list. This makes reporting straightforward: filter Opportunities where Latest_Signed_Contract__c is null to see outstanding contracts.

Example scenario

Example (hypothetical): your team does 200 renewals a month. Each renewal needs a 12-page amendment plus product tables. Automating generation and signature cuts repetitive work — reps no longer copy rows into a doc manually, and Finance sees the signed contract attached to the Opportunity the moment a signer finishes. Instead of a four-day signature chase, the e-signature flow kicks off automatically and writes the signed PDF back to the Opportunity.

Common admin pitfalls and how to avoid them

  • Trigger loop: make sure the Flow only runs when StageName changes to your target value, not on every update.
  • Missing related data: if your template expects child rows, ensure your Flow fetches OpportunityLineItems and passes them to the Action. Savvy DocuGen handles repeating rows natively, but the Flow must supply the parent record id.
  • Storage choice: if your org still uses Notes & Attachments by default, switch templates to write files to Salesforce Files to avoid 25 MB limits.
  • Signer identity: decide whether a one-time code is sufficient or whether you need the per-signer password that can be read from a Salesforce field.

What Savvy DocuGen gives you here

Savvy DocuGen fills Word and PDF templates from any Salesforce record (standard or custom), supports parent and child data for repeating rows, bundles templates into one signature run, sends via your Circularo account, and writes signed PDFs back to the same record. It connects via an authorised connection (no managed package), and works the same in sandboxes as in production.

If you want to try this in your sandbox, set up a Record-Triggered Flow on Opportunity, prepare a Word template with signature anchor tags, and connect your sandbox to Savvy DocuGen. Try it in your sandbox.

Read next