Products
Document Generation
Generate any doc from Salesforce in 1 click
Template Editor
Conditional Logic
Batch Processing
Native E-Signature
Dochly Storage
Connect cloud storage to any Salesforce record automatically
Industries
🏥
Healthcare
HIPAA native
🏦
Financial Services
🏛️
Government
💻
Technology
🏭
Manufacturing
View all 9 industries →
Departments
📈
Sales
Close deals faster
⚙️
Business Operations
💬
Customer Service
👥
Human Resources
📍
Field Service
View all 8 departments →
Resources
Blog
Case Studies
About Dochly
Help Centre
Contact Us
Dochly Storage Pricing Start Free Trial
Generate Documents in Salesforce: Step-by-Step Guide 2026
How to generate documents in Salesforce step by step: complete guide from template to finished PDF
How-To Guide Document Automation Salesforce Native Step-by-Step

How to Generate Documents in Salesforce: Step-by-Step Guide (2026)

How to generate documents in Salesforce is one of those questions that seems straightforward until you try it. The platform holds all your customer data, your deals, your products, your contact details. The document you need requires all of that information. Yet Salesforce has no built-in way to push that data into a Word document or PDF without a dedicated tool.

This guide walks through exactly how document generation works in Salesforce, what you need to get started, and the complete step-by-step process from template to finished document. Every step is based on how a native Salesforce document generation tool works in practice.

If you are new to the concept, start with our overview of what Salesforce document generation is. If you are ready to follow the steps, read on.

What do you need before generating documents in Salesforce?

The first thing to understand about how to generate documents in Salesforce is that it requires a dedicated AppExchange app. You also need administrator permissions to create templates and buttons, and at least one Salesforce object with populated records to generate from. Salesforce does not include document generation as a core platform feature.

When choosing a tool, the most important architectural question is whether it is native or integration-based. Native tools run entirely inside Salesforce using Apex and Lightning. Integration-based tools connect via API from an external server, which means your Salesforce data leaves the platform on every generation event.

  • A document generation app installed and configured in your Salesforce org
  • Administrator permissions or permission to create and edit document templates
  • At least one Salesforce object with records you want to generate documents from
  • A document template to work from, or a blank Word file to build one

How to generate documents in Salesforce: the complete step-by-step process

How to generate documents in Salesforce involves six steps: building a template with merge fields, connecting it to a Salesforce object, adding a generation trigger, testing the output, generating the first live document, and optionally configuring e-signature. Most teams have their first document generating within a few hours of setup.

Step 1: Build your document template

The document template defines the layout, content, and structure of every document your tool will generate. You build it once, insert merge fields where Salesforce data should appear, and the tool uses it every time that document type is requested.

The template is the foundation of how to generate documents in Salesforce. Start with the structure of the document: for a contract, that means sections for parties, terms, payment schedule, and signatures. For an invoice, it means a header, line item table, totals, and payment instructions.

Next, insert merge fields. A merge field is a placeholder that tells the generation tool where to pull data from Salesforce. The syntax varies by tool, but the logic is consistent: you reference the object name and the field's API name.

Common merge field examples {{Account.Name}} — account or company name {{Opportunity.Amount}} — deal or contract value {{Contact.Email}} — primary contact email {{Contract.StartDate}} — contract start date {{Owner.Name}} — account owner full name {{Account.BillingCity}} — billing city from account

The field name you use must be the API name of the field, not the label. To find a field's API name, go to Setup, open Object Manager, select the relevant object, and click Fields and Relationships. Custom fields always end in __c.

For documents with line items — invoices, quotes, purchase orders — use a repeat block to generate one row per related record. The result is a dynamically-sized table that grows or shrinks based on the number of line items on the record.

Salesforce document template setup with merge fields: how to place dynamic field placeholders in a Word template

Merge fields in a document template reference Salesforce field API names. At generation time, each placeholder is replaced with the live value from the record.

For a detailed explanation of merge field syntax, relationship traversal, conditional blocks, and date formatting, see our Salesforce merge fields beginner guide with examples.

Read more: What Is Salesforce Document Generation? The Complete Guide (2026)

Step 2: Connect the template to a Salesforce object

Connecting the template to a Salesforce object tells the generation tool which record to use as the data source when a user triggers generation. A contract template connects to the Opportunity or Contract object. An invoice template connects to the Opportunity or a custom billing object. An offer letter connects to the Contact or a custom candidate object.

At this stage you also configure three things that affect every document generated from this template:

Output format

PDF is standard for documents that will be distributed or signed, because the formatting is preserved regardless of the recipient's software. Word format is useful when the generated document needs further editing before it goes out.

File naming convention

Most tools allow dynamic file names using merge fields. A naming convention like Contract_{{Account.Name}}_{{Contract.StartDate}}.pdf produces a unique, readable filename automatically for every document generated.

Storage location

Native tools store the generated document as a Salesforce File attached to the originating record automatically. No manual download, rename, or re-upload required. The document appears in the Files related list on the record the moment generation completes.

Step 3: Add a generation button or Flow trigger

For users to generate documents, they need a trigger — either a button on the record page layout or a Salesforce Flow that fires automatically based on a record event. Buttons are the most common starting point. Flows are the path to full automation.

Generate PDF from Salesforce record using a custom button on the page layout

A generation button on the record page layout is the simplest trigger. One click, and the document generates and attaches to the record automatically.

To add a custom button in Salesforce, go to Setup and open the Object Manager for the relevant object. Select Buttons, Links, and Actions, and create a new button. Configure it to call the document generation tool's action or Lightning component, then add it to the relevant page layout or Lightning record page.

For automated generation without any user click, use a Salesforce Flow. A record-triggered Flow can fire when an Opportunity moves to Closed Won, when a contract record is created, or when a specific field changes. The Flow calls the document generation action as one of its steps.

Salesforce document generation Flow automation: trigger document creation from a Salesforce Flow

Salesforce Flow integration means document generation can run automatically on any record event — no manual trigger required.

For recurring batch cycles, Flows can be scheduled. A scheduled Flow set to run on the first of each month can generate all monthly invoices, attach them to the correct records, and trigger delivery to recipients before anyone on the team has started their day.

Step 4: Test the template before going live

Before rolling the template out to your team, generate a test document from a real record and verify every merge field, every conditional block, and every line item table resolves correctly. A template that works perfectly on one complete record may produce unexpected output on a record with missing data, a different record type, or a different currency.

Run at minimum these four test cases:

  • A record with all fields populated — confirms the baseline template works end to end
  • A record with optional fields blank — confirms blank fields produce empty space rather than the raw merge field token
  • A record with multiple related child records — confirms the line item repeat block generates the correct number of rows
  • A record with zero child records — confirms the repeat block handles an empty list without breaking the document layout

Most template errors come from field API name mismatches. If a merge field appears blank in the output, check whether the API name in the template exactly matches the field name in Object Manager. A single character difference breaks the field resolution silently — there is no error message, just an empty space in the document.

Step 5: Generate your first document from a Salesforce record

With the template built and tested, knowing how to generate documents in Salesforce from any record takes seconds. Open the record, click the generation button, confirm any settings if prompted, and the document generates and attaches automatically.

The exact sequence is:

1

Open the Salesforce record

Navigate to the record you want to generate a document from. This could be an Opportunity, Contact, Contract, Case, or any custom object your template is connected to.

2

Click the generation button

Click the document generation button on the page layout or run the action from the related list. If the tool supports multiple templates on the same object, you will be prompted to select the correct one.

3

Confirm settings if needed

Some tools offer a confirmation step where you can choose the output format, override the file name, or set recipient details for e-signature. If you have pre-configured defaults, this step may not appear.

4

Document appears on the record

With a native tool, the finished PDF or Word file appears in the Files related list on the Salesforce record within a few seconds. No download, no re-upload. The document is already attached, named correctly, and ready to send or sign.

Step 6: Set up e-signature for the generated document

For most documents, the final step in how to generate documents in Salesforce end-to-end is configuring e-signature. If your document generation tool includes native e-signature, you can configure the signing workflow as part of the generation step so a user can generate and send for signature in a single action.

Set up the following in the template or tool configuration:

  • Signer fields in the template — designate where each signer's signature, initials, date, and any required fields appear
  • Authentication method — email link, one-time passcode (OTP), or identity verification depending on your compliance requirements
  • Signing order — define whether signers sign sequentially or in parallel
  • Certificate of Completion — confirm the tool generates and stores a tamper-evident Certificate of Completion back to Salesforce automatically when signing is complete

With a native tool, the signing experience is handled inside Salesforce's trust boundary. Signing events — who viewed the document, when, from which IP address, using which authentication method — are recorded as Salesforce records in your org. The completed document and its Certificate of Completion are stored as Salesforce Files on the linked record.

Tools that use a third-party signing service store those audit records externally. For teams in HIPAA, SOX, or GDPR environments, that distinction matters. See our post on Salesforce document compliance audit trails for the full picture.

How do you generate documents in bulk from a Salesforce list view?

To generate documents in bulk from a Salesforce list view, select the records you want to process, click the bulk generation button, choose a template, and the tool generates a separate document for each selected record simultaneously. Each document is populated from its own record's data and attached to that record automatically.

The same template used for single-record generation works for batch runs. There is no separate batch template — the difference is only in how the trigger fires. Instead of clicking a button on one record, you select multiple records in the list view and trigger generation for all of them at once.

For teams generating hundreds of documents per month — renewal campaigns, invoice runs, HR cohort onboarding, compliance certifications — batch generation is the feature that makes the tool genuinely valuable at scale. For a detailed look at how this works and what it saves, see our guide on bulk document generation in Salesforce.

What are the most common problems when generating Salesforce documents?

When learning how to generate documents in Salesforce, the most common problems are blank merge fields, missing related record data, documents not attaching to the record, and formatting that breaks in the output. All four have straightforward fixes.

Problem Most likely cause Fix
Merge field shows blank in output API name mismatch between template and Salesforce field Check the exact API name in Object Manager and update the template to match. Custom fields end in __c.
Related record data not appearing Incorrect relationship path in the merge field Use the correct relationship traversal syntax for your tool. Check the tool's documentation for how to reference child objects and lookup fields.
Document not attaching to the record Storage configuration set to download rather than attach Check the template storage settings. Set the output destination to attach as a Salesforce File on the triggering record.
Formatting breaks in PDF output More common with integration-based tools that process externally Native tools that handle formatting inside Salesforce produce more consistent output. If using an integration tool, check for unsupported Word styles in the template.
Line item table shows wrong row count Repeat block not configured for the correct child object Verify the repeat block references the correct API name of the related list. Check that the parent-child relationship is set up correctly on the template.

Frequently asked questions about generating documents in Salesforce

Can Salesforce generate documents automatically?
Yes, Salesforce can generate documents automatically when a native document generation tool is installed and connected to a Salesforce Flow. You can trigger generation on record creation, field updates, button clicks, or scheduled times. The document generates, attaches to the record, and can be sent for e-signature without any manual steps from your team.
How do I create a PDF from a Salesforce record?
To create a PDF from a Salesforce record, install a document generation app from the AppExchange, build a template with merge fields referencing the record's field API names, and add a generation button to the record page layout. When the button is clicked, the tool merges live Salesforce data into the template and saves a PDF to the record automatically. With a native tool, this happens inside Salesforce with no data leaving the platform.
What is a merge field in Salesforce document generation?
A merge field in Salesforce document generation is a dynamic placeholder in a document template that gets replaced with a live field value from a Salesforce record when the document is generated. For example, a merge field referencing Account.Name is replaced with the actual account name from the record at generation time. Merge fields reference the field's API name, which you can find in Object Manager under Fields and Relationships.
How do I generate documents in bulk from a Salesforce list view?
To generate documents in bulk from a Salesforce list view, you need a document generation tool that supports batch processing. Select the records you want in the list view, click the bulk generation button, choose a template, and the tool generates a separate document for each selected record simultaneously, attaching each to its corresponding Salesforce record. The process runs asynchronously so it does not lock your browser while the batch completes.
Does Salesforce have a built-in document generator?
Salesforce does not have a built-in document generator as a core platform feature. Document generation requires a dedicated AppExchange app. Native apps built on Apex and Lightning process documents inside your Salesforce org with no data leaving the platform. Integration-based apps connect from external servers, which means your Salesforce data travels outside the org on every generation event. For regulated industries, the architectural distinction matters significantly.

How to generate documents in Salesforce does not have to be complicated. With the right tool, the process from building a template to generating a live document takes a few hours, not days. The key decisions are which tool to use and whether it runs natively inside Salesforce or relies on an external server.

For everything you need to know before choosing a tool, see our complete guide on what Salesforce document generation is, or visit Dochly document generation to see what a fully native implementation looks like.

Umer Balaj
11x Salesforce Certified Developer and Architect
Umer Balaj is an 11x Salesforce Certified Developer and Architect with 11,000+ hours of Salesforce delivery on Upwork (Top Rated Plus, 100% Job Success). He built Dochly as a 100% native Salesforce document generation and e-signature app. Umer specialises in Apex, LWC, Flows, and complex integrations across Health Cloud, Financial Services Cloud, Sales Cloud, and Service Cloud.