Back to the blog

Build Word templates that repeat child records and pull parent data from Salesforce

Templates 7 min read 24 September 2026

The problem in two sentences

You open a 20-line quote and your Word template spits out one blank table row and 19 empty pages. Or it pulls the Opportunity name but not the parent Account fields you need on page one. Templates that mix repeating child records and multi-level parent lookups are where most admins hit problems.

This guide shows how to design Word templates that repeat child rows reliably, grab parent lookup data up to five levels, and avoid the common layout and pagination traps.

Plan the template around your data model

Start in Salesforce. Look at the record that will trigger the document (Opportunity, Quote, Contract, a custom object __c). Then list every related object you need in the doc. Typical example:

  • Main record: Opportunity (header fields like Name, Close Date)
  • Parent data: Account (billing address, tax ID), and maybe Account.Parent
  • Child records: OpportunityLineItem (product, qty, price) as a repeating table
  • Signer contact: Contact for name and email

Concrete scenario: you generate 150 quotes a month. Each template must render up to 20 line items and include the Account billing address. If you don’t map those relationships up front you’ll be chasing missing fields during testing.

Design the repeating table rows for child records

Word tables are the right tool for line items. The key idea is: create one “pattern” row with merge placeholders — DocuGen will repeat that row for each child record.

Template table layout

Create a table with a header row (column titles) and exactly one pattern row beneath it. Put merge placeholders in the pattern row cells. For example:

| Item # | Description            | Qty | Unit Price | Line Total |
|--------|------------------------|-----|------------|------------|
| {{LineItem.Number}} | {{LineItem.ProductName}} | {{LineItem.Quantity}} | {{LineItem.UnitPrice}} | {{LineItem.LineTotal}} |

That single row is what repeats. Don’t add extra empty rows to “allow for more items” — they turn into real rows when merged and cause blank lines or page breaks.

Sorting and totals

  • Sort child records in Salesforce-derived queries or in the data source feeding the merge so they appear in the order you want.
  • Put totals outside the repeating row. If your table needs a running subtotal next to each row, include a calculated field in the child record or pre-calc a field in the data layer instead of relying on Word formulas for every merged row.

Pull parent lookups across levels

DocuGen can pull up to five levels of parent lookups. That lets you put Account.Parent fields or even higher-level company information on the document without extra automation. Still, be explicit in your template about which lookup you need.

Practical mapping rule

  • If you need Account.Parent.Name, name the placeholder so it’s clear: {{Account.Parent.Name}} (or whichever notation your team uses).
  • Test each level during template build. The first time you add a new parent lookup you’ll find fields that are null on test records — account for that with conditional sections (below).

Handle conditional sections and optional child sets

Not every Opportunity has discounts, extended payment terms or a second signatory. Add conditional sections instead of blank blocks:

  • Wrap optional paragraphs in an if-condition that checks a field (for example, Discount_Amount__c > 0).
  • For optional child lists, keep the repeating table; it will disappear if there are zero child rows. If you need a placeholder message when empty, add a separate paragraph that appears only when the child-count is zero.

Pagination, anchors and images

Large tables push content to new pages. If you place a signature near the bottom of a page use anchor tags for signature positions rather than fixed coordinates — anchor tags survive repagination. Place signer anchors inside paragraphs that move with the text.

Avoid embedding huge images in the template. If the final document can exceed Salesforce Notes & Attachments 25 MB cap, save to Files instead — DocuGen supports Files up to 40 MB.

Testing checklist for admins (quick)

  • Use a sandbox record with the maximum expected child rows (example: 20 line items) and large field values.
  • Check parent lookup fields across up to five levels.
  • Verify conditional sections show and hide correctly.
  • Confirm the table repeats exactly once per child and there are no stray empty rows.
  • Test signature anchors in a multi-page output to ensure they land on the intended page.
  • Make sure finished documents are filed to the right record and stored where your org expects (Files vs Notes & Attachments).

Common pitfalls and how to avoid them

  • Blank extra rows — don’t build fixed rows for anticipated items; use one pattern row only.
  • Null parent fields — add conditional text or default values so the document layout doesn’t break when a lookup is empty.
  • Wrong signer placement after page changes — use anchor tags, not fixed coordinates.
  • Large images causing Notes & Attachments to fail — choose Files when PDFs can exceed 25 MB.

Designing a template is mostly about planning and testing. If you map the exact objects you need, keep one pattern row for repeating child records, and validate parent lookups across levels, the template will behave predictably when you run it from an Opportunity, Quote or Contract.

Savvy DocuGen fills Word and PDF templates from any Salesforce record, supports child and grandchild repeating rows, reaches five levels of parent lookups, and keeps signature anchors intact when content repaginates. Try Savvy DocuGen in your sandbox to build and test your template with real records and confirm the output on Files or Notes & Attachments.

Read next