Back to the blog

Automate Salesforce document generation from Opportunity records

Document Generation 5 min read 21 September 2026

The problem: manual document creation from Opportunity and Contract

You open an Opportunity, copy 20 fields into a Word contract, save as PDF, upload it to the record, then email it to the customer. That process is repeated for every deal and every renewal. It breaks on field errors, forgotten clauses, and the right pricing attachment that lives on a child Quote record.

If you have a 60-page agreement, 200 renewals a month and a four-day signature chase, that manual approach costs your team time and creates audit headaches. You need Salesforce document generation that pulls the right fields, child lines and related Account data without me typing a single value.

Why Salesforce document generation fixes this

Good document generation removes the copy-paste step and does two things reliably: it fills approved templates from Salesforce data, and it files the finished document back where your team expects to find it. That means fewer version mistakes, accurate data in the legal document, and a clear audit trail on the Opportunity or Contract record.

Common admin stumbling blocks

  • Templates live in shared drives and get edited without approval—so you can’t be sure which wording sales used.
  • Line-items or pricing live on Quote and QuoteLineItem, not on Opportunity, so copying fields misses detail rows.
  • Attachments: your org uses Notes & Attachments and Salesforce Files inconsistently; Documents over 25 MB won’t save to Notes & Attachments.
  • Signatures: PDFs get emailed, then signed outside Salesforce and manually refiled.

How to stop copy-paste: merge templates in Salesforce

Set up a Word template that uses merge tags for fields you want to fill from Opportunity, Account, Contact, Quote and custom objects. Then configure the generation step to run from the Opportunity page or a Flow. The result is a filled Word or PDF file that’s automatically saved back to the record.

What a practical setup looks like

  • Create a Word template with merge placeholders for: Opportunity fields, related Account fields, the primary Contact, and repeating rows for QuoteLineItem if you want line-by-line pricing.
  • Map parent lookups: pick fields up to five levels of parent records (for example, Opportunity > Account > Parent Account => Region).
  • Map child records into repeating table rows so the same template can populate a 10-line or a 200-line quote without changing the template.
  • Save the finished document to Salesforce Files when the generated PDF exceeds 25 MB; otherwise Notes & Attachments also works.
  • Trigger the generation from a button on the Opportunity page, from a stage change in a Flow, or when a supporting file is uploaded.

Example: generating a renewal contract

Hypothetical situation: you run 200 renewals per month and each renewal needs a 60-page contract with product line items from the child Quote object. Set a Flow that triggers when the Opportunity Stage changes to "Renewal Ready": it pulls Account billing data (parent lookup), the primary Contact, and the QuoteLineItem children. The Flow calls the template, generates the PDF, saves the file to the Opportunity, then sends it for signature.

Merge templates in Salesforce: things to get right

Templates are simple, but the correct mapping and storage behaviour matter. Here are the admin-level details that stop things breaking at scale.

Field and hierarchy mapping

Make sure your template references the exact field names you expect. Keep templates stable by using fields that exist in every record you’ll run the template on—avoid optional custom fields unless you know how to handle blanks.

Repeating rows from child objects

Use the repeating-table feature so QuoteLineItem rows appear as table rows in Word or PDF. That prevents you from manually copying pricing into a document or maintaining multiple templates for different line counts.

File size and storage

Documents up to 40 MB can be generated and stored, but Notes & Attachments is capped at 25 MB. If your contract includes annexes or full product spec PDFs, save to Salesforce Files by default.

Signatures that survive repagination

Place signature anchors in the Word template rather than fixed page coordinates. Anchors follow the signature tag through repagination so signers land in the right place even if the document length changes.

Signature identity and security

If you need stronger signer identity, require an emailed one-time code and a per-signer password read from that signer’s Salesforce Contact record. That keeps the identity verification tied to your CRM data.

How this looks for an admin: clicks, not code

The typical admin flow is:

  1. Upload a Word template with merge tags for Opportunity, Account, Contact and Quote data.
  2. Configure which related lists populate repeating rows (pick QuoteLineItem, for example).
  3. Choose where the finished file is stored: Files or Notes & Attachments.
  4. Decide the trigger: add a button to Opportunity page, or have a Flow run when Stage changes.
  5. Optionally bundle additional templates (cover, SOW, annex) and send them in one signature run.
// Example placeholder in your Word template
{{Opportunity.Name}}  
{{Account.BillingAddress}}  
{{Contact.Email}}

That code-like snippet shows the idea: human-friendly placeholders in Word that the generator replaces with Salesforce data.

Wrap-up and next step

If your org is still hand-building contracts from Opportunity fields and Quotes, moving to merge templates in Salesforce saves time, reduces rework and makes filing and signing predictable. Savvy DocuGen fills Word and PDF templates from any Salesforce record (including five levels of parent lookups and child repeating rows), saves the finished file to Files or Notes & Attachments, and sends for signature through your Circularo account with anchor-tagged signature positions. It works in sandboxes exactly as in production and can be triggered by a button, stage change, field change or new file.

Try it yourself: upload a template and run a generation in your sandbox to see how much time you get back.

Read next