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

Named Query Structure

Learn the required tags, merge field pattern, and format-specific syntax for named queries.

Use this page when you need exact syntax for a named query block.

Model

<!--{{!
<lineitemsSOQL>
  <queryname>TopLineItem</queryname>
  <soql>
    SELECT Name, Quantity, TotalPrice
    FROM OpportunityLineItem
    WHERE OpportunityId = '{{!Opportunity.Id}}'
    ORDER BY TotalPrice DESC
    LIMIT 1
  </soql>
  <filter id="1">TotalPrice >= 1000</filter>
</lineitemsSOQL>
}}-->
1

<!--{{! and }}-->

Purpose

These are S-Docs processing block markers.

  • <!--{{! tells S-Docs to start processing the block

  • }}--> tells S-Docs to stop processing the block

They also keep the block hidden if the template is opened outside S-Docs.

2

<lineitemsSOQL>

Purpose

This wrapper tells S-Docs to run a SOQL query during document generation.

For named queries, the goal is usually data reuse, not table output.

Key traits:

  • runs a SOQL query at generation time

  • can return one row or many rows

  • lets you reuse returned values later in the template

3

<queryname>

Purpose

This assigns the reusable name for your query result.

<queryname>TopLineItem</queryname>

You will reference this name later in merge fields.

For example:

{{!TopLineItem.Name}}

Rules:

  • use a unique name in the template

  • keep the name short and descriptive

  • match the spelling exactly in later merge fields

4

<soql>

Purpose

This contains the exact SOQL query S-Docs should run.

<soql>
  SELECT Name, Quantity, TotalPrice
  FROM OpportunityLineItem
  WHERE OpportunityId = '{{!Opportunity.Id}}'
  ORDER BY TotalPrice DESC
  LIMIT 1
</soql>

This example returns the highest-value line item for the current opportunity.

Use <soql> when you need:

  • specific fields

  • filtering with WHERE

  • sorting with ORDER BY

  • one-row results with LIMIT 1

  • aggregates like COUNT() or SUM()

Include every field you plan to reference later.

5

<filter>

Purpose

<filter> lets you define reusable conditions inside the same named query.

<filter id="1">TotalPrice >= 1000</filter>

You can then call that filter in a merge field:

{{!FilteredItems.Name filter="1" offset="1"}}

Use filter when you want multiple output variations from one result set.

6

Merge field syntax

Purpose

After the query runs, reference values with this pattern:

{{!QueryName.FieldName}}

Examples:

  • {{!TopLineItem.Name}}

  • {{!TopLineItem.Quantity}}

  • {{!LineItemStats.asum #,###.##}}

  • {{!FilteredItems.Name filter="1" offset="2"}}

Common parts:

  • QueryName comes from <queryname>

  • FieldName must come from the SELECT clause

  • formatting comes after a space

  • filter and offset are optional attributes

Merge field quick reference

Pattern
Use

{{!QueryName.FieldName}}

Return a field from the first matching row

{{!QueryName.FieldName #,###.00}}

Format a numeric value

{{!QueryName.FieldName filter="1"}}

Apply a named filter

{{!QueryName.FieldName offset="2"}}

Return the second row

{{!QueryName.FieldName filter="1" offset="2"}}

Combine both

Format-specific variations

Wrap both the query block and the merge fields in square brackets.

  • Query block: [{{!<lineitemsSOQL>...</lineitemsSOQL>}}]

  • Merge field: [{{!QueryName.FieldName}}]

Place the query block in the template's Named Queries setting.

Then place merge fields like {{!QueryName.FieldName}} on the PDF surface.

Summary table

Part
Meaning

<!--{{! / }}-->

Starts and ends S-Docs processing

<lineitemsSOQL>

Wraps the named query block

<queryname>

Sets the reusable query name

<soql>

Runs the actual SOQL query

<filter>

Adds reusable filter logic

{{!QueryName.FieldName}}

Reuses a returned value later

Full example

Last updated

Was this helpful?