Back to the blog

Step-by-Step Guide to Creating Custom Document Templates in Salesforce

Document Generation 8 min read 29 July 2026

Introduction

Creating custom document templates in Salesforce helps automate the generation of contracts, quotes, and other important documents. Savvy DocGen integrates with Salesforce to streamline this process using your Salesforce data. This article walks you through building a custom document template from scratch.

Prerequisites

  • Salesforce user with permissions to manage objects and fields
  • Savvy DocGen installed and configured in your Salesforce org
  • Basic knowledge of Salesforce objects and fields

Step 1: Plan Your Template Content

Before building your template, decide what data and layout you need. Identify the Salesforce object records you want to pull data from. For example, if you are generating a sales proposal, you may need data from the Opportunity and Account objects.

Identify Key Fields

  • Opportunity Name
  • Account Billing Address
  • Opportunity Amount
  • Close Date

Sketch a rough layout of the document, noting where each field should appear.

Step 2: Create a Template File

Savvy DocGen supports Microsoft Word (.docx) templates. Start with a blank document or an existing template.

  • Open Microsoft Word
  • Create the static content (headings, paragraphs, logos)
  • Leave placeholders where dynamic data will appear

Example placeholder text: {{Opportunity.Name}}

Step 3: Insert Merge Fields

Use merge fields to link Salesforce data to the template. The syntax is {{ObjectName.FieldName}}. Savvy DocGen replaces these placeholders with actual data during generation.

Common Merge Field Examples

  • {{Account.Name}} — Account name
  • {{Opportunity.CloseDate}} — Opportunity close date
  • {{User.FullName}} — Salesforce user full name

Handling Related Objects

You can access fields on related objects using dot notation. For example, to get the billing city from the Account related to an Opportunity, use {{Opportunity.Account.BillingCity}}.

Step 4: Upload Template to Salesforce

Once your template is ready, upload it into Salesforce through Savvy DocGen's interface.

  1. Go to the Savvy DocGen Templates tab
  2. Click New Template
  3. Fill in the template name and select the related Salesforce object
  4. Upload your Word document
  5. Save the template

Step 5: Test Document Generation

Test your template by generating a document for a sample record.

  1. Navigate to a record of the Salesforce object you selected
  2. Use the Savvy DocGen button or action to generate a document
  3. Review the generated document for accuracy

Check that all merge fields correctly populate with Salesforce data.

Step 6: Refine and Add Conditional Logic

To improve your template, add conditional blocks to show or hide sections based on data. Savvy DocGen supports simple conditional syntax.

Example: Show a discount section only if a discount exists

{{#if Opportunity.Discount__c}}
Discount Applied: {{Opportunity.Discount__c}}
{{/if}}

This syntax shows the discount section only when the discount field is not empty.

Best Practices

  • Use clear and consistent naming for merge fields
  • Keep templates simple to reduce errors
  • Test templates with multiple records to handle variations
  • Use tables and styles in Word for better formatting
  • Keep conditional logic minimal and well documented

Conclusion

Building custom document templates in Salesforce with Savvy DocGen is a straightforward process. With planning, correct merge field syntax, and testing, you can automate document creation and improve consistency. Follow these steps to get started and refine your templates as your business needs evolve.

Read next