Expression generator, context object and field paths

The context object

Every template has a context object: the primary Salesforce object the document is about (for example Contact, Account, or Opportunity). It is stored on the Template and set in the builder, either through the Expression Generator or the Publisher.

When the document is opened, the link supplies a record Id of that context object. All merge fields resolve against that record. So a template with context object Account, opened for a specific Account record, renders that Account's data.

Merge expression anatomy

Every dynamic value in a template is an expression of the form:

#{TYPE:CODE>FORMATTER}

The forms:

Kind Expression Meaning
Field merge #{Account.Id:Owner.Name} On the context Account, follow the field path Owner.Name.
Field merge with formatter #{Account.Id:Amount>CurrencyGBP} Merge Amount, then format it with the CurrencyGBP formatter.
Function #{Functions:Signature} Run a function expression. See Function expressions.
URL parameter #{Params:contractRef} Insert the value of a URL parameter. See Custom URL tags.
Repeat seed #{^OpportunityLineItem.OpportunityId:Id} Start a repeat block over related child records. See Repeat sections.

You rarely type these by hand. The builder generates them.

The Expression Generator

Open the Expression Generator from the Field expressions toolbar button. It walks you through building a field merge:

  1. Context object - the document's context object. Changing it here updates the template's context object.
  2. Merge object - either the context object itself or a related object you want data from.
  3. Field path - drill down to the exact field, following relationships as far as you need (for example Account.Owner.Name).

Then use:

You can also type # in the document to quickly pick a field from the current context object.

Field paths and relationships

A field path can follow relationships across objects. Owner.Name reaches the owning user's name from the context record. Account.Owner.Name reaches from a Contact to its Account to that Account's owner. The generator loads the fields of each object as you drill, so you build valid paths without knowing the schema by heart.

For polymorphic relationships, the path follows the primary related object.

How resolution works at render

When the document renders, the engine groups all the field expressions by object and queries Salesforce for exactly the fields needed, filtered to the context record. The returned values are placed into the document. Invalid field paths are flagged in place so you can spot and fix them, rather than failing silently.

Fields can also be merged into element attributes (not just visible text), which is how dynamic links, images, and styling driven by data are built.

Tips