For admins and template authors: combine several templates, such as a proposal and its terms and conditions, into one generated document instead of maintaining one large template. Setup takes about 10 minutes if the solution already works with one template.
Before you begin
- A document solution that works with its main template. See Document Automation Wizard: every step explained.
- The other templates, built on the same Salesforce object, with merge fields that the solution's Gather Data setup can fill. See Template syntax basics.
- Templates in formats your edition supports. Basic uses Word (.docx) templates and generates Word or PDF. PDF forms need Pro (DME-LIC-002). See Compare editions.
How it works
The MergeDocument parameter tells a solution to process all of its templates and merge them into one document, in the order they are configured. The solution must contain more than one template. Each template keeps its own formatting in the merged file.
You can also combine Word templates and PDF forms: the output is one PDF. PDF forms need Pro.
There are three related ideas on this site. Use this table to pick the right one:
| If you need… | Use… |
|---|---|
| The same set of templates combined every time, for example a proposal plus terms and conditions | MergeDocument=1 on the solution (this guide) |
| A second template chosen at generation time, for example the terms for the record's region | A QVar that returns the template ID, plus MergeDocument=1. See Use QVars. |
| To merge documents from different sources into one | Global Merge, added in v1.19.0. It's a separate feature: you create a solution on the Document Global Merge object, not a parameter on this solution. |
Add the templates to the solution
- Open the solution in the wizard and go to the Add Template page.
- Add the main template, for example
Proposal, and the template that follows it, for exampleTerms and Conditions. - Drag the templates into reading order. The merged document follows this order.
- Check that all the templates appear in the solution's Templates section, then click Next.
Turn on MergeDocument
- On the Assign Behaviors page, click Other Parameter in the sidebar, then click Add Other Parameter.
- Enter
MergeDocumentas the name and1as the value. - Click Save.
To start each template on a new page, end each template (except the last) with {{_PageBreak_}}. See PageBreak.
Verify it worked
- Open a record of the solution's object and click the solution's button.
- Generate the document. You get one file, not one per template.
- Check that the first pages contain the main template and the following pages contain the next template, each with the record's data merged in.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| You get only one template's content | The solution contains one template, or MergeDocument isn't saved | Add the other templates, and check the Other Parameter list shows MergeDocument = 1. |
| The templates are in the wrong order | They're configured in a different order in the solution | Drag them into reading order on the Add Template page. See MergeDocument. |
| The second template's fields are blank | Its fields come from a relationship or query the solution doesn't gather | Add the relationship on Gather Data. See Merge fields are blank or show tags. |
| "Document is too large to process" | A template file is too large (templates can be at most 5 MB) | Compress images or split the template. See DME-DOC-001. |
| "… merge is not allowed in this basic version" | One template is a PDF form, Excel or PowerPoint file on a Basic license | Use Word templates or upgrade. See DME-LIC-002. |
Next steps
- Use QVars to choose the second template from record data at generation time.
- docfamily to group related templates.
- Where generated documents go to choose where the merged file is saved.