Data Routing: How to dynamically select templates using formula fields (Part 1)

Category :
How To

Published: June 2, 2026

Docs shouldn’t be complicated.

With Docs Made Easy, creating professional, Salesforce-powered documents is just a few clicks away.

Get Started Now

Many organizations need different documents at different stages of the sales cycle. Manually selecting the correct document template for every record can slow processes down and increase the risk of generating the wrong document.

In this step-by-step guide, we will solve this challenge by configuring Salesforce document generation to automatically select the appropriate template based on Opportunity Stage. Whether you need a contract template, proposal template, or invoice template, the correct document can be generated from a single data source.

Create Three Templates

Step 1: Create the following three templates:

  • Contract Template 
  • Proposal Template 
  • Invoice Template

After successfully creating these templates, copy their respective IDs. Use these IDs while creating the formula field.

 


Creating Formula Field 

Step 1: Click on the Gear (⚙️) icon in the top-right corner, then select Setup from the dropdown menu.

 


Step 2: Click on Object Manager.

 


Step 3:
In the Quick Find search bar, type Opportunity, then select Opportunity from the search results.

 


Step 4:
Click on Field & Relationship.

 


Step 5:
Click on New Button.

 


Step 6
: Select Formula as the data type, then click Next.

 


Step 7
: Enter the Field Label as “Multiple Template Id”, then select Text as the formula return type. After that, click Next.

 


Step 8:
Enter the CASE function to return Template IDs based on Opportunity Stage.

Enter the CASE formula as follows:

CASE(

   StageName,

   “Prospecting”, “Contract_Template_Id”,

   “Closed Won”, “Invoice_Template_Id”,

   “Closed Lost”, “Proposal_Template_Id”,

   “Default_ID”

Explanation:

  • When Stage = Prospecting → returns Contract Template ID 
  • When Stage = Closed Won → returns Invoice Template ID 
  • When Stage = Closed Lost → returns Proposal Template ID 
  • If none match → returns Default ID

Click On Next

 


Step 9:
Click Next again, then click Save to create the field successfully.

 

Watch Live Demo

 

Conclusion

By mapping Opportunity stages to specific template IDs through a formula field, you can automate document generation and eliminate the need for manual template selection. This creates a more consistent and efficient document workflow.

This approach helps ensure the right document is generated at the right time while simplifying Salesforce document generation processes across your sales lifecycle. It also makes managing multiple templates easier as your business requirements grow.

Frequently Asked Questions

When the Opportunity stage changes, the formula automatically returns a different template ID. With Docs Made Easy, users can generate updated documents matching the latest stage requirements.
Yes, advanced formula conditions can include additional fields such as region, business unit, or product type, helping Docs Made Easy support more personalized document generation workflows.
No, Salesforce formula fields provide a declarative approach. Combined with Docs Made Easy, administrators can automate template selection without writing custom Apex code or integrations.
Absolutely. Administrators can update template IDs within the formula field whenever needed, allowing Docs Made Easy to continue generating documents without disrupting existing workflows.
Yes, automation eliminates repetitive template selection tasks. By leveraging Docs Made Easy, sales teams spend less time on documentation and more time engaging customers.

Related Blogs


How To

How to Create a Static Resource in Salesforce for Document Generation

Creating static resources in Salesforce is important when you need to store reusable files like images, text files, or HTML…

Read more
How To

How to Generate Letters in Salesforce

Creating professional letters directly within Salesforce can often become time-consuming when handled manually. Businesses today need a faster and more…

Read more
How To

How to Set Up the QVar Parameter for Dynamic Document Templates in Salesforce

If you want your document generation process to dynamically display templates based on specific record data, setting up the QVar…

Read more