For the complete documentation index, see llms.txt. This page is also available as Markdown.

Adding Tables (Like Products or Contacts) to Your Document

Build a simple related-record table pattern you can adapt to many S-Docs templates.

Example output

Your finished document can look like this:

Opportunity
Stage
Close Date
Amount

Renewal - Northwind

Proposal/Price Quote

2026-05-15

25000

Expansion - Northwind

Negotiation/Review

2026-06-01

40000

Services Add-On

Qualification

2026-06-20

12000

What You'll Learn

  • Build a related list table from a parent record

  • Query Opportunity records from an Account template

  • Match table headers to <column> tags in the right order

  • Test the output before adding filters

  • Reuse the same pattern with other object pairs

What You'll Build

In this tutorial, you will build an account pipeline summary that lists related opportunities in a table.

This walkthrough uses Account as the base object and Opportunity as the child object.

The finished template will include:

  • An account summary header

  • A four-column opportunity table

  • A related list query tied to the current account

  • One safe variation that only shows open opportunities

Estimated time: 15 minutes

Prerequisites

Before you start, make sure you have:

  • Access to S-Docs Templates in Salesforce

  • Permission to create or edit templates

  • A template related to Account

  • A test account with at least two related Opportunity records

  • Basic familiarity with merge fields such as {{!Account.Name}}

If you want a shorter intro first, use Insert Data Tables.

1

Step 1: Open or create the template

Start with an Account template so the query can use the current account ID.

  1. Go to S-Docs Templates.

  2. Open an existing template or click New Template.

  3. Set Related To Type to Account.

  4. Open the template editor.

You now have a base template that can query child records from the current account.

2

Step 2: Add the account summary header

Add a small header first.

This confirms your base merge fields resolve before you add the related list.

What you just did:

  • Confirmed the template runs from Account

  • Added visible fields to test the base record context

  • Created a simple header above the opportunity table

3

Step 3: Add the table shell

Create the visible table structure first.

Then place the query block inside the table body.

What you just did:

  • Defined the columns the reader will see

  • Left space for the related list query

  • Created a reusable table layout for child records

4

This example uses Opportunity as the child object.

It pulls records related to the current Account.

What this does:

  • Queries Opportunity records for the current account

  • Ties the query to the base record with WHERE AccountId = '{{!Account.Id}}'

  • Sorts the rows by CloseDate

  • Prints one field per <column> tag

How to read the block:

  • <lineitemsSOQL> starts the related list query

  • <class> controls the output style

  • <soql> defines which child rows to return

  • Each <column> prints one value in the row

5

Step 5: Match the headers and columns

The table only works cleanly when the header order matches the <column> order.

In this example:

  • Opportunity maps to Name

  • Stage maps to StageName

  • Close Date maps to CloseDate

  • Amount maps to Amount

Rules to follow:

  • Every displayed value needs a matching <column> tag

  • Every <column> value must appear in the SELECT clause

  • The first header must match the first <column>

If the order does not match, the wrong values appear under the wrong headers.

6

Step 6: Save and test the template

Test the base version before you add any variations.

  1. Click Save.

  2. Open a test account with related opportunities.

  3. Generate the document.

  4. Compare the document rows with the related records in Salesforce.

Verify these results:

  • The header shows the expected account

  • The table shows one row per related opportunity

  • The rows belong to the current account only

  • The values appear under the correct headers

Once this works, you have a reusable starting pattern.

7

Step 7: Try one simple variation

Now add one safe filter.

This version only returns open opportunities.

What changed:

  • Added AND IsClosed = false

  • Kept the same table structure

  • Narrowed the output without changing the base pattern

Change one thing at a time.

Then generate again and confirm the result.

Common Issues and Solutions

"My table shows no rows"

Check these items:

  • Confirm the template runs from Account

  • Confirm the test account has related Opportunity records

  • Verify the WHERE clause uses AccountId = '{{!Account.Id}}'

  • Test with a record you know has child records

"My values are under the wrong headers"

Check these items:

  • Compare the header order with the <column> order

  • Make sure each header has one matching query field

  • Add fields one at a time when expanding the table

"One column is blank"

Check these items:

  • Verify that field appears in the SELECT clause

  • Verify the same field appears in the matching <column> tag

  • Confirm the returned records actually contain data in that field

"The wrong records are returned"

Check these items:

  • Review the relationship field in the WHERE clause

  • Confirm the base merge field points to the current record

  • Remove extra filters and test the base query first

"How do I adapt this to another object pair?"

Use this swap pattern:

  • Change the base template object

  • Change the child object in FROM

  • Change the relationship field in WHERE

  • Change the selected fields, headers, and <column> tags together

Keep the overall table structure the same.

What You've Learned

✅ Built a related list table from an Account template ✅ Queried Opportunity records with <lineitemsSOQL> ✅ Tied the query to the current base record ✅ Matched headers to <column> tags in the correct order ✅ Reused one example pattern that can scale to other objects

Next Steps

Adapt the pattern

  • Replace Opportunity with Contact on an Account template

  • Change the visible columns for a different use case

  • Add one more field and test it by itself

Combine it with other features

Practice Exercise

Build an Account template that includes:

  1. A header with Account.Name and Account.Owner.Name

  2. A four-column related list table for opportunities

  3. One query tied to the current account

  4. A test run against an account with related opportunities

  5. One filtered variation that only shows open opportunities

Bonus challenges:

  • Rebuild the same pattern for Account and Contact

  • Change the sort order

  • Add one more displayed field

Last updated

Was this helpful?