You are here:
Context Service for Document Generation
Starting Winter '26, Context Service is the default token mapping method in Salesforce Document Generation (DocGen). It provides a visual way to extract and organize business data from different sources without an Omnistudio license. It then connects that structure to Salesforce data using context mappings. With Context Service, you define the structure of the data you want to use in your documents, making it easier to generate accurate, personalized content across contracts, quotes, and other business documents. When a document is generated from a document template, Context Service replaces the tokens with real data from the mapped fields.
Required Editions
| Available in: Lightning Experience |
| Available in: Professional, Enterprise, Unlimited, and Developer Editions |
Why Use Context Service
- Extract and transform data for document generation.
- Generate token data for contracts, quotes, orders by using a single context definition that can be mapped to different entities for different use cases.
- Customize output for different business processes by reusing the same context definition with different mappings.
- Include images, hyperlinks, and editable fields in templates by using supported token naming conventions.
Key Features of Context Service
- Use a single context definition across multiple templates and business objects by creating reusable mappings.
- Supports document generation through the Contract UI, Document Generation Process (DGP), batch document generation, and APIs.
- When using Document Templates from an Omniscript, templates using Context Service are supported only in Single Doc Core – DOCX Server-side (LWC) OmniScript. Note: Omniscripts require an Omnistudio license.
- Context definitions and templates can be manually migrated between orgs. ContentDefinitions aren’t included by default in document template migration and must be migrated separately, similar to Omni DataMappers.
- Data true-up tokens are automatically linked to their associated object, field, and value—no additional configuration required.
Note
- When using DGP, set the Additional Input Type to Context Service and provide the entity ID to generate the document.
Benefits of Using Context Service
- No additional licenses like Omnistudio required for document generation.
- One context definition can support multiple templates.
- The same context definition can be reused across documents with similar structures, such as Contracts, Quotes, and Orders by applying different context mappings.
- Reduces setup duplication across business processes.
- Supports rich content such as images, hyperlinks, and live field updates.
- Image, hyperlink, and data true-up tokens are automatically identified and processed during document generation.
- Tokens pull directly from related objects such as, Quote.Account.Name, QuoteLineItem.Product2.Name.
- Line items are grouped automatically using repeated sections in the template.
Sequence to Complete Context Service Token Mapping Method Configuration for Document Generation
- Create a context definition by defining the necessary nodes and attributes that represent your data structure. You can also clone or extend a custom context definition.
- Map the definition by connecting each node and attribute to the appropriate Salesforce or custom object fields.
- Activate the context definition to make it available for selection in document templates.
- Design a document template by inserting tokens that align with your defined structure.
- Generate the document by triggering the process through the API, user interface, or a Flow, to resolve and populate the data.
- Token Naming Conventions for Context Service
Use naming conventions to correctly insert image, hyperlink, rich text, and data true-up tokens in your document templates. Each token follows a specific format so that Context Service can identify the type of content and process it correctly during document generation. - Enable Context Service and Provide Permissions
To use Context Service for document generation, first enable the Context Service feature in your org and ensure users have the required permissions. - Context Definition for Document Generation
Define a reusable data structure for document templates by creating context definitions. These definitions organize Salesforce business data into nodes and attributes, capture relationships such as primary and related objects, and map the information into a structured JSON format. The mapped data provides token values used in document generation. - Context Mapping for Document Generation
Map the structure defined in a context definition to actual data sources so document templates can retrieve values at runtime. A context mapping links each node and attribute to specific Salesforce fields and objects. When editing a context mapping, use Edit SObject Mapping to access and update the appropriate mapping. Make sure to update the input mapping as well to keep it in sync. Make sure the input mapping names match the attribute names. If they don’t match, data for those attributes won’t be hydrated. - Create a Document Template by Using Context Service for Document Generation
Upload and configure a Microsoft 365, Microsoft Word or PowerPoint template. Then, use Context Service to replace tokens with Salesforce data during document generation. - Example: Generating a Contract Document by Using Context Service
Understand how Context Service can streamline contract document generation by mapping structured Salesforce data to template tokens. This setup supports dynamic content, hyperlinks, images, and live updates using a reusable context definition and mapping. Review the context definition structure, mapping, and JSON output that illustrate how Context Service can support contract document generation. It includes elements such as dynamic content, hyperlinks, images, and live updates by using a reusable context definition. - Example: Generating a Proposal from a Quote by Using Context Service
Review the context definition structure, mapping, and JSON output that illustrate how Context Service can support proposal generation from a Quote record. It includes possible elements such as account details, billing information, product line items, and a company logo. - Troubleshooting for Token Replacement Issues When Using Context Service for Document Generation
In some cases, documents are generated with missing or partially populated token values. Use the checklist below to identify and resolve common issues related to Context Service token mapping. - Limitations of Context Service for Document Generation
Context Service has some functional limitations compared with Omnistudio data mappers. Consider these limitations when using Context Service for document generation.
Did this article solve your issue?
Let us know so we can improve!

