# How to Create Dynamic File Names

Use dynamic file names to replace generic outputs like `SD-0001.pdf`.

This makes files easier to sort, search, and identify in Salesforce.

### Set the output file name

{% stepper %}
{% step %}

### Open document options

Open the **Document Options** tab in the Template Editor.
{% endstep %}

{% step %}

### Find the file name setting

Locate **Attachment & File Name Options**.
{% endstep %}

{% step %}

### Enter the naming formula

Add your formula in **Output File Format**.
{% endstep %}

{% step %}

### Save and test

Save the template.

Generate a test document.
{% endstep %}
{% endstepper %}

{% hint style="warning" %}
Use single braces in file name formulas: `{!Object.Field}`.

Do not use standard body merge field syntax like `{{!Object.Field}}`.
{% endhint %}

### Common naming patterns

| Use case     | Formula                                    | Example output                     |
| ------------ | ------------------------------------------ | ---------------------------------- |
| Sales quotes | `Quote-{!Opportunity.Name}-{!TODAY()}.pdf` | `Quote-Q1 Services-2024-02-04.pdf` |
| Invoices     | `INV-{!Opportunity.InvoiceNumber__c}.pdf`  | `INV-12345.pdf`                    |
| Contracts    | `Contract-{!Opportunity.Account.Name}.pdf` | `Contract-Acme Corp.pdf`           |
| Reports      | `{!Account.Name}-Report-{!TODAY()}.pdf`    | `Acme-Report-2024-02-04.pdf`       |

### Best practices

* Avoid `/`, `\`, `:`, `*`, `?`, `"`, `<`, `>`, and `|`.
* Use hyphens or underscores instead of spaces.
* Keep names under `80` characters when possible.
* Put the most important value first.

### Tips

#### Include record context

Start with the document type, record name, or ID.

This improves sorting in related lists and external storage systems.

#### Add a date when needed

Use `{!TODAY()}` for time-based versioning.

This helps when users generate multiple copies over time.

#### Keep names stable

Avoid long formulas with optional fields unless you need them.

Shorter names are easier to scan.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://help.sdocs.com/sdocs/template-architecture/template-settings/document-options-tab/how-to-create-dynamic-file-names.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
