The problem, short
When you generate documents from Salesforce, two things go wrong most often: parent lookup merge fields come through empty or the wrong record, and repeating table rows (child records) either don’t appear or repeat the same line. These failures make a 60-page Contract or Quote look broken and force people to edit PDFs manually.
Why parent lookup merge fields and repeating table merge fields fail
There are a few common root causes. Knowing which one you’re hitting saves hours of trial and error.
- Wrong field or relationship name - The merge template needs the API relationship name, not the label you see in the page layout. For parent fields you use dotted relationship names (for example Account.Name from an Opportunity). For child records you need the child-relationship name ending in
__r when mapping repeating rows.
- Field-level access - If the generating user doesn’t have access to a field, the merge will be blank. That applies to system fields and formula fields too.
- Depth of relationship - Some tools only pull one parent level. If your template expects Account.Parent.Parent.Name it might return nothing unless the generator supports multiple parent lookups.
- Incorrect repeating table setup - Repeating rows need a clear child relationship and a way to iterate. If your template treats child records like single values, you’ll get either one row or repeated identical rows.
- Document storage limits - Very large documents need Salesforce Files rather than Notes and Attachments. If a merged document exceeds the Notes and Attachments cap you’ll see failures.
Checklist to make Salesforce document templates pull the right data
Work through this checklist as you build and test a template. It’s written for a Salesforce Admin who wants clicks-first steps, not code.
- Confirm the API names and relationship paths
Open Setup - Object Manager and find the object (Opportunity, Quote, Contract). Note the field API name and the parent relationship path. Example: if you want the account parent’s name from an Opportunity use Opportunity.Account.Name. For two levels: Opportunity.Account.Parent.Name.
- Use the child relationship name for repeating rows
Find the child object under the parent and note its child relationship name (often ends with __r for custom objects). In your Word template repeat row use something like:
| Product | Quantity | Unit Price |
| {{Line_Items__r.Product__c}} | {{Line_Items__r.Quantity__c}} | {{Line_Items__r.Unit_Price__c}} |
This tells the generator to loop the Line_Items__r child records and insert each field per row.
- Check field-level security and sharing
Log in as a user who will generate the doc (or use the profile) and verify visibility for every field used in the template. Remember formula fields can be hidden by FLS too.
- Validate multi-level parents
If your document needs deep parent lookups (Account.Parent.Parent...), confirm your generator supports multiple parent levels. Some tools stop at one parent. Savvy DocuGen reaches five levels of parent lookups, so you can safely reference grandparent fields for Opportunity and Contract templates.
- Test with realistic data
Create a sandbox test record that mirrors production complexity. Example scenario: a renewal Opportunity with 10 Line_Item__c child records and Account with a Parent account. Generate the document and confirm each of the 10 rows appears with the right quantities and that the parent account name is correct.
- Choose the right storage target
If your merged file is large - for example a 60-page agreement with many attachments - configure the template to file the result in Salesforce Files. Notes and Attachments is capped at 25 MB and will fail for larger docs.
Template example you can adapt
Here are small, generic examples you can copy into your Word template system. Replace API names to match your org.
Parent lookup example:
{{Opportunity.Name}}
{{Opportunity.Account.Name}}
{{Opportunity.Account.Parent.Name}}
Repeating table example (table row):
{{#each Opportunity.Line_Items__r}}
{{Product__c}} | {{Quantity__c}} | {{Unit_Price__c}}
{{/each}}
This uses dotted parent paths for lookups and a child-relationship loop for repeating rows. The generator will iterate the child records and insert one table row per child.
Testing and common fixes
- Blank parent field - Check the field API name and FLS. If the parent exists in data but is blank in the doc, it’s usually a name mismatch or a permission issue.
- No child rows - Confirm the child records actually point to the parent record via the lookup field. Also ensure the child relationship name is correct in the template.
- Single repeated row - That usually means the template didn’t loop the child relationship; rework the table row into a repeating row block in your template editor.
- Pagination breaks signature placement - Use anchor tags for signature positions. Anchor tags survive repagination so signature boxes land where you expect, even when content shifts.
Quick scenario to test: create a Quote on an Opportunity that includes 8 QuoteLineItems, merge a Quote template that lists line items in a repeating table, and confirm the resulting PDF contains 8 distinct rows, the Opportunity.Account.Parent.Name appears once in the header, and the signed file saves back to the Quote record.
How Savvy DocuGen helps you fix these problems
Savvy DocuGen fills Word and PDF templates from any Salesforce record, supports five levels of parent lookups, and writes child and grandchild records as repeating table rows. It files the finished document back to the source record in Salesforce Files or Notes and Attachments per template, and signature positions use anchor tags so they survive repagination. For e-sign you send through your Circularo account and the signed PDF is written back to the same record.
If you’re an admin ready to stop fixing merged PDFs by hand, try Savvy DocuGen in a sandbox and run the checklist above on a real Opportunity-Account-Child data set.
Read next