You are here:
Context Filters for Document Generation
Document generation often pulls data from complex models that return more records than a document requires. To exclude irrelevant data, use filters to control which data the context service fetches before generating a document. When you add a filter to a template, document generation applies the filter every time a document is rendered.
Required Editions
| Available in: Lightning Experience |
| Available in: Professional, Enterprise, Unlimited, and Developer Editions |
You define context filters in a context definition. Each filter belongs to a single context definition and becomes available automatically when you use that context definition in a document template. Filters are optional. If you don’t select a filter, document generation uses all records returned by the context definition and mapping.
What Context Filters Do
A context filter can refine data in three ways:
- Filter records by using defined conditions
- Sort records by a single attribute
- Limit records returned after sorting
Context filters operate on context nodes and attributes, not directly on Salesforce object fields. These nodes and attributes come from the canonical structure defined in the context definition. All filter conditions use AND logic. The UI doesn’t support OR conditions and complex expressions that combine multiple condition types.
How Context Filters Work with Document Generation
When you generate a document by using context service, it evaluates the context definition and token mapping. It then applies the selected filter and passes the filtered token data to document generation to populate the template.
If you configure a transform plug-in, document generation passes the filtered token data to the transform logic. Filters always apply before transformation. See Transform Token Data with Context Service for Document Generation.
You can create context filters to refine line items included in a document. For example, you can:
- Filter quote line items based on quantity or price thresholds.
- Sort filtered items in descending or ascending order.
- Limit the output to the most relevant records for the document.
When you generate the document, only the filtered and sorted line items appear. The template layout doesn’t change. Only the data passed into the template changes.
Scope and Support
- You can select only one context filter per document template.
- Filters apply only to future document generations.
- Filters don’t modify Salesforce data.
- Document generation supports context filters only when the context service is the token mapping method.
- Document generation in the Omnistudio managed package doesn’t support context service or context filters.
- Apply a Context Filter for Document Generation
Apply a filter to a template to control which data the context service fetches each time the template is used to generate a document. A context filter can refine data by applying defined conditions, sort records by a single attribute, or limit the number of records returned after sorting. - Context Filter Capabilities and Limits
Review supported capabilities and limits for context filters in Salesforce Document Generation. - Using a Context Filter Versus a Transform Plug-In for Document Generation
Understand when to use a context filter or a transform plug-in in document generation.

