---
title: "Select templates based on record field values"
url: "https://docs.signnow.com/docs/salesforce-select-templates-by-field-values"
type: "page"
section: "Integrations"
slug: "salesforce-select-templates-by-field-values"
---

# Select templates based on record field values

# Select templates based on record field values

Offer Salesforce senders only the templates a record needs by adding formula conditions to a custom button URL.

**Use case overview**

Your company sends loan agreements from Salesforce Accounts. The documents each customer signs depend on the record:

- If **Billing State** is `California`, the sender needs the CA agreement, the disclosure, and the addendum.
- If **Payment Frequency** is `Weekly`, the sender also needs the weekly payment addendum.

Instead of creating a template for every combination, create one template per document and one custom button. The button URL contains a Salesforce formula that adds a template ID for each condition the record meets. When the sender clicks the button, SignNow offers only the templates that match that record.

```mermaid
%%{init: {'themeVariables': {'fontSize': '16px'}, 'flowchart': {'rankSpacing': 30, 'nodeSpacing': 20, 'padding': 8}}}%%
flowchart LR
    State{"California?"}
    Freq{"Weekly?"}
    AddCA["Add CA agreement,<br>disclosure, addendum"]
    AddWeekly["Add weekly<br>payment addendum"]
    Result["Offer the<br>added templates"]

    State -- "Yes" --> AddCA --> Freq
    State -- "No" --> Freq
    Freq -- "Yes" --> AddWeekly --> Result
    Freq -- "No" --> Result
```

Follow the steps below to configure this setup in Salesforce.

## Step 1. Create the templates

Create a separate template for each document you want to send conditionally.

- Go to **SignNow Admin Tools** > **Templates** > **Create New Template**.
- Upload the document, add fillable fields and recipients, and click **Done**.
- Repeat for each document. In this example, the templates are **CA agreement**, **disclosure**, **addendum**, and **weekly payment addendum**.

To learn how to add fillable fields and recipients and set up pre-fill, see [Templates](/docs/templates).

On the **Templates** tab, the **Template ID** column shows the ID of each template. You will use these IDs in the formula.

![Templates tab in SignNow Admin Tools listing four templates with their Template IDs](/reference-assets/images/SignNow_Salesforce/use_case_template_conditions/templates_list_ids.png)

## Step 2. Generate a custom link with all templates

- In **SignNow Admin Tools**, click **Custom Links**.
- Select **Templates: pre-selected by the Admin**.
- In **Select Template**, select every template the button can offer. In this example, select all four.
- Optionally, add a document flow to apply preset recipients and sender settings to the documents. See [Add the SignNow document flow](/docs/custom-links#add-the-signnow-document-flow-optional).
- Enter the API name of the object where you will add the button (`Account` in this example).
- Click **Copy link**.

![Custom Links tab with Templates: pre-selected by the Admin and four templates selected in the Select Template list](/reference-assets/images/SignNow_Salesforce/use_case_template_conditions/custom_links_preselected.png)

The copied link lists the template IDs in the `template_group_id` parameter, separated by `%2C`, the URL-encoded comma.

![Generated custom link for the Account object with four template IDs in the template_group_id parameter](/reference-assets/images/SignNow_Salesforce/use_case_template_conditions/custom_link_generated.png)

The end of the link is the part you replace in the next step. Example of the generated `template_group_id` value for the four templates in this use case, with placeholders instead of real template IDs:

`template_group_id=<weekly_payment_addendum_id>%2C<addendum_id>%2C<disclosure_id>%2C<ca_agreement_id>`

## Step 3. Add conditions to the link

In the link you copied in Step 2, delete everything after `template_group_id=` and replace it with Salesforce formula expressions, one per condition. When the sender clicks the button, Salesforce evaluates each expression against the record and inserts the result into the link. SignNow receives only the template IDs whose conditions are true.

### How an expression works

Each condition is an `IF` expression wrapped in `{! }`. This expression adds the three California templates:

```text
{!IF(Account.BillingState = "California", "<ca_agreement_id>%2C<disclosure_id>%2C<addendum_id>%2C", "")}
```

| Part | What it does |
| --- | --- |
| `{! }` | Marks a formula. Salesforce calculates it when the sender clicks the button and puts the result in the link. |
| `IF(condition, value_if_true, value_if_false)` | Returns the second value when the condition is true and the third value when it is false. |
| `Account.BillingState = "California"` | The condition. The value in quotes must match the value stored in the field, for example `California` or `CA`. |
| `"<id>%2C<id>%2C<id>%2C"` | The template IDs to add when the condition is true. Copy the IDs from the **Template ID** column in Step 1 and end each one with `%2C`, the URL-encoded comma. |
| `""` | An empty value, so nothing is added when the condition is false. |

Write the condition to match the field type:

- **Text field**: compare with `=`, for example `Account.BillingState = "California"`.
- **Picklist**: use `ISPICKVAL()`, for example `ISPICKVAL(Account.Payment_Frequency__c, "Weekly")`.

To avoid typing field names by hand, build the expression in the **Custom Button or Link Editor**: select the field in **Insert Field** to add its merge field, and pick `IF` or `ISPICKVAL` from **Functions**. For the syntax of every function you can use in a condition, see [All Formula Operators and Functions](https://help.salesforce.com/s/articleView?id=sf.customize_functions_parent.htm&language=en_US&type=5) in Salesforce Help.

### Combine several conditions

Place the expressions one after another, with nothing between them. Salesforce joins their results, so a record that meets both conditions gets all four template IDs.

Example of the `template_group_id` value that Salesforce sends to SignNow for an Account with Billing State `California` and Payment Frequency `Weekly`:

`template_group_id=<ca_agreement_id>%2C<disclosure_id>%2C<addendum_id>%2C<weekly_payment_addendum_id>%2C`

Because every ID ends with `%2C`, the IDs stay separated whichever conditions are true.

In this example, **Payment Frequency** is a custom picklist field (`Payment_Frequency__c`) on the Account. Replace the field names and IDs with your own. If the record doesn't have a field for your condition yet, create one in **Setup** > **Object Manager** > *object* > **Fields & Relationships** > **New**, and use its API name, ending in `__c`, in the formula.

For step-by-step instructions on creating a custom field, including picklist values, field visibility, and page layouts, see [Create a Custom Field](https://help.salesforce.com/s/articleView?language=en_US&id=sf.adding_fields.htm&type=5) in Salesforce Help.

The complete link with both conditions looks like this. Use it as the URL of the custom button in Step 4:

```text
/apex/cuda_signnow__universal_signnow?app_path=/en/sender&contextId={!CASESAFEID(Account.Id)}&contextTable=Account&initialDirectory=/Account/{!CASESAFEID(Account.Id)}&sources=template&template_group_id={!IF(Account.BillingState = "California", "<ca_agreement_id>%2C<disclosure_id>%2C<addendum_id>%2C", "")}{!IF(ISPICKVAL(Account.Payment_Frequency__c, "Weekly"), "<weekly_payment_addendum_id>%2C", "")}
```

The link adds the following templates:

| Billing State | Payment Frequency | Templates offered |
| --- | --- | --- |
| California | Weekly | CA agreement, disclosure, addendum, weekly payment addendum |
| California | Any other value | CA agreement, disclosure, addendum |
| Any other value | Weekly | Weekly payment addendum |
| Any other value | Any other value | All templates in the SignNow account |

> [!NOTE]
> When no condition matches, `template_group_id` is empty and the sender can choose from every template in the account. To keep the sender within a set of templates, add an expression that returns a default template ID when none of the other conditions is true.

You can add as many `IF` expressions as you need, and base them on any field available in the object's formula editor.

## Step 4. Add the button to the object

Create a custom button with the modified link as its URL and add it to the page layout. For the button settings and where to place the button, see [Add the custom button to the Salesforce object](/docs/custom-links#add-the-custom-button-to-the-salesforce-object).

You can use the same approach on any object. Generate the link with that object's API name and reference its fields in the conditions.

## Step 5. Explore the user experience

When the sender clicks the button, Salesforce evaluates the conditions against the record, and SignNow offers only the templates that match. The **Select Templates** screen lists the matching templates. The sender selects the ones to send, sets their order in **Merge order** if needed, and clicks **Proceed**. The selected templates are combined into one document in the order shown.

> [!NOTE]
> If you add a document flow in Step 2, it can change what the sender sees after clicking the button, depending on the flow configuration. For example, if the document flow hides the template selection step, all templates that match the conditions open for the sender as one document group. To choose which steps the sender sees, see [Configure the sender's experience](/docs/document-flows#configure-the-senders-experience).

For an Account in California with monthly payments, the sender sees the three California templates.

![Select Templates screen listing addendum, CA agreement, and disclosure, with the Merge order panel](/reference-assets/images/SignNow_Salesforce/use_case_template_conditions/select_templates_california.png)

For an Account in California with weekly payments, the sender sees all four templates.

![Select Templates screen listing four templates, including weekly payment addendum, with the Merge order panel](/reference-assets/images/SignNow_Salesforce/use_case_template_conditions/select_templates_california_weekly.png)


---
*Full page: https://docs.signnow.com/docs/salesforce-select-templates-by-field-values*
