---
title: "Build document templates in Salesforce"
canonical_url: "https://www.nutrient.io/guides/salesforce-documents/admin-guide/build-document-templates-in-salesforce/"
md_url: "https://www.nutrient.io/guides/salesforce-documents/admin-guide/build-document-templates-in-salesforce.md"
last_updated: "2026-06-05T20:16:40.286Z"
description: "Configure datasets, placeholders, merge fields, collections, conditions, and dynamic data inputs for Nutrient document templates in Salesforce."
---

# Build document templates in Salesforce

Use this guide to configure the data model behind a Nutrient template so generated documents can pull the right Salesforce data.

## Who should use this guide

This guide is for developers and administrators who build or maintain templates in Template Manager.

## Prerequisites

Before you begin, confirm that:

- The basic Nutrient Documents for Salesforce setup is complete

- Your user has the **Nutrient Manage Templates** permission

- At least one document template already exists

- You can open that template in **Template Manager**

If you still need access or setup, refer to the [set up Nutrient Documents for Salesforce](https://www.nutrient.io/guides/salesforce-documents/admin-guide/set-up-documents-for-salesforce.md) and [manage document templates in Salesforce](https://www.nutrient.io/guides/salesforce-documents/admin-guide/manage-document-templates-in-salesforce.md) guides.

## Understand the dataset model

The dataset defines the dynamic content used during document creation. It includes these building blocks:

- **Merge fields** — Single values such as names, dates, or amounts

- **Collections** — Repeating groups such as line items or related records

- **Conditions** — Rules that show or hide content

- **Placeholders** — The tags that you place in the template document

- **Data inputs** — The Salesforce data sources behind the dataset

Predefined data inputs include:

- **Salesforce Record** — The root record and its related records

- **Current User Data** — Information from the user generating the document

- **System Data** — Values such as current date or fiscal year (available only for merge fields)

You can also add dynamic data inputs so users can select records during document creation. Collections and dynamic data inputs don’t offer System Data as a data input option.

Placeholder names support letters, numbers, underscores (`_`), and dots (`.`).

## Navigate Salesforce relationships

Use navigation steps to move through Salesforce relationships when you build merge fields, collections, or dynamic inputs.

1. Add or edit a dataset item.

2. Click **Add Navigation Step**.

3. Choose the related record type that you want to move into.

4. Repeat as needed until you reach the field or collection that you want.

The relation field appears in brackets, so you can distinguish between multiple relationships to the same object.

If a navigation step returns a one-to-many relationship, you can also:

- Filter the collection

- Sort the collection

- Group filters

- Use multiple sort rules

Navigation, filtering, and sorting support custom fields, custom objects, and custom relationships in your Salesforce organization.

## Add merge fields

Use merge fields when you need to insert a single value into the document.

This example shows how a merge field placeholder looks in a template:

```text

Opportunity stage: {{opportunity_stage}}

```

To add a merge field, follow these steps:

1. In the dataset view, click **Add**.

2. Select **Add merge field**.

3. Choose the data input.

4. Navigate to the Salesforce field that you want.

5. Enter the placeholder name.

6. Click **Save**.

After you save the merge field, you can use the item menu to:

- Edit the field

- Reorder it

- Duplicate it

- Delete it

- Copy its placeholder

- Insert it into the document at the cursor position

### Format merge fields and set fallback values

Use formatting and fallback values to control how merge fields render in the final document.

For supported field types, you can apply Salesforce standard formatting, including:

- Dates

- Date and time values

- Currency

- Numbers

- Percentages

You can also define a default value for nullable or empty fields.

Currency formatting with symbol plus ISO currency code is supported only for single-currency organizations. Number formatting for currency values is supported in all organizations.

## Add collections

Use collections when the template should repeat content for multiple records.

This example shows how collection placeholders wrap repeating content:

```text

{{#line_items}}

Name: {{line_item_name}}; Amount: {{line_item_amount}}
{{/line_items}}

```

To add a collection, follow these steps:

1. In the dataset view, click **Add**.

2. Select **Add collection**.

3. Navigate to the collection of records that you want to loop through.

   Make sure the final navigation step ends in a child collection. If the navigation ends in a lookup field, you can’t create the collection.

4. Optional: Apply filters and sorting.

5. Enter the collection placeholder name.

6. Click **Save**.

After you create the collection, add merge fields inside it for the values that you want to render for each record.

1. Open the collection menu.

2. Add a merge field inside the collection.

3. Choose the field that you want to add.

   If you add navigation steps for a merge field inside a collection, make sure the final step ends in a child field. If it ends in a lookup field, you can’t create the merge field.

4. Save the merge field.

When you finish, the collection appears in the dataset sidebar with its nested merge fields.

Collection placeholders aren’t rendered in the final document. Only the content inside them repeats.

### Use automatic collection helpers

Each collection includes helper placeholders that you can use directly in the template or in conditions.

These helpers are:

- `collection.length()` — Returns the number of items

- `collection.isEmpty()` — A condition that is true if the collection has no items

## Add conditions

Use conditions to show or hide content based on Salesforce data.

This example shows how true and false condition blocks work in a template:

```text

{{#is_opportunity_open}}

Opportunity stage: {{opportunity_stage}}.
{{/is_opportunity_open}}

{{^is_opportunity_open}}
Opportunity is closed.
{{/is_opportunity_open}}

```

To add a condition, follow these steps:

1. In the dataset view, click **Add**.

2. Select **Add condition**.

3. Choose the data input that the condition should belong to.

4. Enter the placeholder name.

5. Select the field or condition to compare.

6. Select the comparison value, field, or condition.

7. Optional: Group multiple comparisons to build more complex logic.

8. Click **Save**.

Conditions can compare:

- Field values

- Custom values

- Existing conditions

Comparison behavior adapts to the selected field type, so dates, numbers, and text can be compared appropriately. String comparisons are case-insensitive, and date/datetime comparisons use the date portion only.

Condition scope depends on where you create it:

- **Root-level conditions** can reference fields and conditions at the root of the same data input, plus root-level fields and conditions from other data inputs.

- **Collection-level conditions** can reference fields and conditions in the same collection item, plus parent/root fields and conditions from the same data input and root-level fields and conditions from other data inputs.

- Conditions can’t reference data inside another collection or other items in the same collection.

Conditions nested inside collections can’t be combined outside their parent collection.

When you insert conditions into the document:

- Use `{{#condition_name}}` for content that should render when the condition is true

- Use `{{^condition_name}}` for content that should render when the condition is false

- Close the block with `{{/condition_name}}`

Condition placeholders aren’t rendered in the final document. Only the enclosed content renders when the rule matches.

## Add dynamic data inputs

Use dynamic data inputs when users need to select one or more Salesforce records during document creation.

To add a dynamic data input, follow these steps:

1. In the dataset view, click **Add**.

2. Select **Add data input**.

3. Choose whether the input should come from:
   - A record related to the root Salesforce record
   - The current user
   - A list of unrelated Salesforce records

4. Navigate to the record or collection that users should choose from.

   Make sure the final navigation step ends in a child collection. If the navigation ends in a lookup field, you can’t create the data input.

5. Enter the placeholder name.

6. Click **Save**.

After you save the dynamic input, you can add merge fields or collections under it just as you would for the root Salesforce record.

### Edit dynamic data inputs and picker labels

Use the item menu when you need to update an existing dynamic input.

You can make a material navigation change only when the dynamic input has no merge fields or collections defined under it. If merge fields or collections already exist, you can still edit filters and sorting on each navigation step, but you can’t change the navigation itself.

If the dynamic input already contains merge fields, you can choose one of those fields to represent the record in the runtime picker. Merge fields whose navigation includes a collection don’t appear in the dropdown.

The following image shows the error message that appears when you try to change the navigation with existing merge fields or collections:

## Related guides

Refer to the following guides for related tasks:

- [Set up Nutrient Documents for Salesforce](https://www.nutrient.io/guides/salesforce-documents/admin-guide/set-up-documents-for-salesforce.md)

- [Manage document templates in Salesforce](https://www.nutrient.io/guides/salesforce-documents/admin-guide/manage-document-templates-in-salesforce.md)

- [Create documents in Salesforce](https://www.nutrient.io/guides/salesforce-documents/end-user-guide/create-documents.md)
---

## Related pages

- [Manage document templates in Salesforce](/guides/salesforce-documents/admin-guide/manage-document-templates-in-salesforce.md)
- [Set up document generation in Salesforce](/guides/salesforce-documents/admin-guide/set-up-document-generation-in-salesforce.md)
- [Set up Nutrient Documents for Salesforce](/guides/salesforce-documents/admin-guide/set-up-documents-for-salesforce.md)
- [Set up digital signing in Salesforce](/guides/salesforce-documents/admin-guide/setup-signing-integration-with-dws.md)

