How to Render Nested Salesforce Relationships in Documents

Learn how to render parent-child-grandchild Salesforce data structures in business documents without flattening your data or writing custom code.
Most Salesforce document generation tools handle flat data well. Give them an Opportunity with a few fields and a line-items table, and they produce a clean output.
The problem starts when your document needs to reflect how data actually lives in Salesforce - layered, relational, and hierarchical.
A wealth management client summary is not flat. A loan application package is not flat. A portfolio review with accounts, holdings, and asset categories is not flat.
This article walks through how to render multi-level Salesforce relationships in documents using ZeroExport, without flattening your schema or writing custom Apex.
Why Nested Data Breaks Traditional Document Tools
Traditional document generators are built around a single primary object and one level of related lists. They work well for simple scenarios:
- Opportunity → Line Items
- Contact → Activities
- Case → Comments
When you need a second or third level of nesting, you hit a wall. Most tools require you to:
- Pre-flatten the data into a custom object or a report
- Write Apex or middleware to denormalize the structure
- Maintain multiple templates for each data variant
The result is brittle logic spread across your org that breaks when data changes.
What a Nested Document Structure Looks Like
Consider a financial services client summary. The natural Salesforce structure looks like this:
Client (Account)
└── Portfolios (custom object related to Account)
└── Holdings (custom object related to Portfolio)
└── Asset Categories (custom object related to Holding)
In a document, you want to render this as:
- Client header with account details
- Each portfolio as a named section
- Holdings listed under each portfolio
- Asset category breakdown under each holding
This is a four-level hierarchy. Traditional tools cannot render this without data transformation.
Step-by-Step: Configure Nested Data Sources in ZeroExport
1. Add the Primary Data Source
Open the Data source editor from the left rail in the ZeroExport builder and select your root object. For a client portfolio summary, this is the Account (or Client custom object).
Select the fields you need at the top level:
- Client Name
- Client ID
- Relationship Manager
- Date of Report
2. Add the First Child Relationship
Still in the Data source editor, add the first related object, Portfolios, as a child of Account.
Select the fields needed for portfolio-level rendering:
- Portfolio Name
- Portfolio Type
- Total Market Value
- Currency
ZeroExport tracks the relationship path automatically so child data stays bound to the correct parent record.
3. Add the Second Child Relationship
Add Holdings as a child of Portfolio. Select:
- Holding Name
- ISIN or Ticker
- Units Held
- Current Value
- Weight (percentage of portfolio)
At this level, ZeroExport establishes the second nesting tier. Holdings will render within their respective portfolio block automatically.
4. Add the Third Child Relationship (Optional)
For detailed asset category breakdowns, add Asset Categories as a child of Holdings:
- Category Name
- Sub-category
- Allocation Percentage
This gives you a four-level data hierarchy without custom code or pre-flattening.
5. Build the Repeating Portfolio Section
In the template builder, add a repeating section bound to the Portfolio data source.
Inside this section, add:
- A portfolio header with name and total value
- A repeating table bound to Holdings
- Summary fields (total allocation, total value)
Each portfolio record creates its own section in the output document, rendered with its own holdings data.
6. Add Nested Holdings Table Inside Portfolio Section
Inside the portfolio repeating section, insert a table bound to the Holdings child data source.
Columns:
| Holding Name | Ticker | Units | Current Value | Weight |
|---|---|---|---|---|
{holding.name} | {holding.ticker} | {holding.units} | {holding.value} | {holding.weight} |
The table renders only the holdings that belong to the current portfolio iteration, not all holdings across all portfolios.
7. Preview with a Real Salesforce Record
Use the Test Bench to run a preview against a real Account record with multiple portfolios and holdings:
- Select an Account record
- Click Preview
- Verify each portfolio renders its own section
- Verify holdings appear under the correct portfolio
- Verify totals calculate per portfolio, not globally
The Output: What Nested Rendering Looks Like
The generated document contains distinct portfolio sections, each with its own holdings table. Client-level information appears once at the top. Asset categories appear under each holding where configured.
Common Mistakes When Working With Nested Data
Binding the child table to the wrong parent context - Make sure your Holdings table is placed inside the Portfolio repeating section, not at the document root level.
Selecting too many fields at the grandchild level - Deeply nested queries can be slow. Select only the fields the document actually renders.
Trying to calculate cross-portfolio totals inside a nested section - Global aggregations should be placed outside repeating sections, bound to the top-level data source.
FAQ
Can ZeroExport handle more than three levels of nesting?
Yes, though document complexity increases significantly at four or more levels. Most enterprise use cases (financial summaries, loan packages, insurance policy packs) work well at two to three levels.
Do I need to write Apex to configure nested data sources?
No. ZeroExport configures nested relationships through the Data Sources UI. No code is required to set up parent-child-grandchild bindings.
How does ZeroExport know which holdings belong to which portfolio?
The relationship path is configured in the Data source editor. ZeroExport uses the Salesforce relationship structure (lookup or master-detail) to scope each child dataset to its parent record during rendering.
Can I calculate subtotals at each nesting level?
Yes. Subtotals can be placed inside repeating sections to aggregate values scoped to that level, for example, portfolio total value calculated from its own holdings.
Related Reading
Ready to try ZeroExport?
Start generating documents directly in your Salesforce org. No integrations, no setup overhead, no complexity.