When it comes to generating professional quote documents in Salesforce Revenue Cloud, you have multiple options. While Document Builder offers a native drag-and-drop experience, Context Service with OmniStudio Document Generation provides a more powerful and flexible approach—especially when you need to reuse existing data structures from pricing procedures or implement advanced transformations.
In this comprehensive guide, I’ll walk you through everything you need to know about using Context Service for document generation. We’ll cover the architecture, setup process, token conventions, filters, and build a complete quote proposal template from scratch.
What You’ll Learn
- What Context Service is and why it’s the modern approach to document generation
- How to enable and configure document generation settings
- Working with Context Definitions and Context Mappings
- Token naming conventions for different content types
- Creating and applying Context Filters
- Building a Screen Flow to generate documents
- Creating Word templates with repeating content
What is Context Service?
Context Service is a generic data layer module in Salesforce that fetches and organizes business data from Salesforce objects for use across various processes. If you’ve worked with Pricing Procedures in Revenue Cloud, you’re already familiar with Context Service—it’s the same underlying technology that powers both pricing calculations and document generation.
For document generation specifically, Context Service replaces the traditional Data Mapper approach used in older OmniStudio implementations. The key advantage? You can reuse the same SalesTransactionContext definition that your pricing procedures already use, eliminating the need to rebuild your data structure for documents.
Key Benefits of Using Context Service
| Benefit | Description |
| Reuse Pricing Context | The same SalesTransactionContext used by pricing procedures works for document generation |
| Rich Content Support | Images, hyperlinks, rich text, and Data True-Up tokens are all supported |
| Multiple Templates | One context definition can support templates for Quotes, Orders, and Contracts |
| Repeating Content | Line items automatically loop using repeating content tokens |
| Related Object Data | Pull tokens from related objects like Quote.Account.Name |
| Filter Support | Context Filters refine, sort, and limit the data in your documents |
Context Service Architecture
Understanding how the pieces fit together is essential before diving into implementation. Here’s the flow:
- Context Definition – Defines the nodes and attributes (your data structure)
- Context Mapping – Links that structure to actual Salesforce fields
- Document Template – Your Word or PowerPoint file with tokens
- Context Filter (Optional) – Filters, sorts, or limits records
- Transform Plug-In (Optional) – Custom Apex for hierarchies and grouping
- Generated Document – The final output with populated data
Step 1: Enable Document Generation
Before you can create templates, you need to enable document generation in your org. Navigate to Setup → Document Generation → General Settings.
General Settings Configuration
| Option | Purpose |
| Design Document Templates | Enables the template designer within Salesforce |
| Salesforce Contracts Connector | Microsoft 365 Word integration for CLM |
| Document Templates Export | Metadata/Tooling API export capability |
When you enable “Design Document Templates,” Salesforce automatically creates the Docgen Document Template Library where you’ll upload your Word (.docx) and PowerPoint (.pptx) templates.
Assign Required Permission Sets
Make sure users have the appropriate permission sets assigned:
- DocGen Designer – For users creating and managing templates
- DocGen User – For users generating documents
Step 2: Create Document Generation Setting
Navigate to Setup → Document Generation Settings → New to create your configuration record.
| Field | Value | Notes |
| Label | DocGen | Your preferred name |
| Template Library | DocgenDocumentTemplateLibrary | Auto-Created Library |
| Generation Mechanism | Server-Side | Required for Context Service |
| Preview Type | PDF or Thumbnail |
Important: Context Service only supports Server-Side generation. If you need Client-Side generation, you must use Data Mapper instead.
Step 3: Configure Context Definition
If you’re working in a Revenue Cloud environment, you likely already have an active SalesTransactionContext definition that powers your pricing procedures. This same context definition can be extended for document generation.
Navigate to Setup → Context Definitions and select the Custom Definitions tab to view your extended context.
Standard Context Structure
SalesTransaction → Quote
├── SalesTransactionName
├── Account, TotalAmount, Status
└── SalesTransactionItem → QuoteLineItem
├── ProductName, Quantity
└── NetUnitPrice, TotalPrice
Adding Custom Attributes
To add custom fields to your document, you need to extend the context definition with new attributes. For example, to add Account Name from the related account:
- Open your context definition and click Edit
- Navigate to the Sales Transaction node
- Click Add Attribute
- Configure the new attribute:
- Name: AccountName
- Type: Input and Output
- Data Type: String
- Add a corresponding Tag with the same name
- Click Save
This process is similar to what you do when mapping custom fields for quote-to-order transfers or mapping product fields to quote lines.
Step 4: Configure Context Mapping
After adding attributes to your context definition, you need to map them to actual Salesforce fields. Navigate to the Map Data tab and select your Quote Entities Mapping.
Mapping Related Object Fields
To map the AccountName attribute to the related Account’s Name field:
- Click Edit Mapping
- Find your new attribute under Unmapped
- On the right panel, navigate through the relationship: Quote → Account ID → Name
- Select the field and click Save
- Click Save and Publish to activate the mapping
| Attribute | Salesforce Field Path |
| AccountName | Quote.Account.Name |
| TotalPrice | Quote.TotalPrice |
| BillingCity | Quote.BillingCity |
| ProductName | QuoteLineItem.Product2.Name |
Token Naming Conventions
Context Service uses special prefixes for different content types. Understanding these conventions is essential for building effective templates.
| Token Type | Format | Example |
| Standard Text | {{AttributeName}} | {{AccountName}} |
| Image | {{IMG_name_src}} | {{IMG_Logo}} |
| Hyperlink | {{HYP_name_url}} | {{HYP_ProductLink}} |
| Rich Text | {{RTB_name}} | {{RTB_Description}} |
| Date True-Up | {{DT_name}} | {{DT_Amount}} |
Image Token Attributes
For images, you need multiple attributes that Context Service groups automatically:
IMG_Logo_src– ContentDocument IDIMG_Logo_height– Optional heightIMG_Logo_width– Optional width
Data True-Up Tokens
Data True-Up tokens enable live updates from document edits back to Salesforce—perfect for Contract Lifecycle Management scenarios. Note that these only work with parent objects and DOCX templates.
Repeating Content Tokens
For line items like quote products, you need repeating content that automatically loops through each record. The syntax uses opening and closing tags:
{{#SalesTransactionItem}}
{{ProductName}} - {{Quantity}} x {{UnitPrice}}
{{/SalesTransactionItem}}
When building tables in Word:
- Create a table with your column headers in the first row
- In the data row, place
{{#SalesTransactionItem}}before the first cell content - Add your field tokens in each cell
- Place
{{/SalesTransactionItem}}after the last cell content
The table will automatically expand to include all line items when the document is generated.
Step 5: Create Context Filters
Context Filters allow you to control which data appears in your documents. You can filter records by conditions, sort them, and limit the count.
Navigate to your context definition and click on the Filters tab.
Creating a Filter
- Click New Filter
- Enter a name (e.g., “QuoteLineFilter”)
- Add conditions:
- Node: SalesTransactionItem
- Attribute: Quantity
- Operator: Greater than or equal
- Value: 5
- Configure sort order:
- Attribute: Quantity
- Direction: Ascending
- Set record limit (e.g., 10)
- Click Save
Note: Filters use AND logic only—you cannot create OR conditions. Also, you can only apply one filter per template.
Filter vs Transform Plug-In
Both options modify your output data, but they serve different purposes:
| Context Filter | Transform Plug-In |
| Filter out unwanted records | Group by category |
| Sort records | Build hierarchies (bundles) |
| Limit Record Count | Custom Calculations |
| No Code Required | Requires Apex |
| AND Logic only | Full flexibility |
You can use both together: the filter runs first, then the Transform Plug-In processes the filtered data.
Want to dive deeper into Transform Plug-Ins for bundle hierarchies?
The full Revenue Cloud training covers Apex-based data transformations, custom grouping, and advanced document generation techniques.
Step 6: Build the Document Generation Flow
To generate documents, we’ll create a Screen Flow that can be embedded on the Quote record page. The flow will:
- Let users select a template
- Create a DocumentGenerationProcess record
- Display the generated document
Flow Variables and Resources
Create these resources in your flow:
1. Record Variable: recordId
- Type: Record
- Object: Quote
- Available for input: Yes
2. Record Choice Set: DocumentTemplates
- Object: DocumentTemplate
- Filter: Active = True AND Type = “Microsoft Word”
- Choice Label: Name
- Choice Value: Id
3. Formula: RequestTextFormula
"{\"keepIntermediate\":false,\"title\":\"Quote-" & {!recordId.QuoteNumber} & "\"}"
Create Records Element Configuration
Create a record of type DocumentGenerationProcess with these field values:
| Field | Value |
| DocGenAdditionalInput | {!recordId.Id} |
| DocGenAdditionalInputType | ContextService |
| DocumentInputType | DocumentTemplate |
| DocumentTemplateId | {!QuoteTemplateId} |
| ReferenceObject | {!recordId.Id} |
| RequestText | {!RequestTextFormula} |
| Status | InProgress |
| Type | GenerateAndConvert |
Add Flow to Quote Page
- Edit your Quote Lightning Record Page
- Add a Flow component
- Select your document generation flow
- Check “Pass all field values from the record to the flow”
- Save and activate the page
Step 7: Create the Word Template
Now create your Word template using the token naming conventions. Here’s a sample structure:
QUOTE PROPOSAL
Prepared for: {{AccountName}}
Quote Number: {{SalesTransactionName}}
Billing Address:
{{BillingStreet}}
{{BillingCity}}, {{BillingState}}
Products:
┌─────────────────┬──────────┬────────────┬────────────┐
│ Product │ Quantity │ List Price │ Total │
├─────────────────┼──────────┼────────────┼────────────┤
│{{#SalesTransactionItem}}{{ProductName}}│{{Quantity}}│{{ListPrice}}│{{NetTotal}}{{/SalesTransactionItem}}│
└─────────────────┴──────────┴────────────┴────────────┘
Total: {{TotalAmount}}
{{IMG_Logo}}
Upload Template to Salesforce
- Navigate to App Launcher → Design Document Template
- Click New
- Configure the template:
- Name: Quote Template
- Template Type: Word
- Token Mapping Method: Context Service
- Context Definition: SalesTransactionContext
- Context Mapping: Quote Entities Mapping
- Context Filter: QuoteLineFilter (optional)
- Usage Type: Revenue Lifecycle Management
- Upload your Word file
- Click Save and Activate
Testing Your Document Generation
With everything configured, test the complete flow:
- Navigate to a Quote with line items
- Open the Document Generation tab
- Select your template
- Click Next to generate
- The document is automatically attached to the Quote’s Notes & Attachments
If you configured a filter (e.g., Quantity >= 5), you’ll notice that only qualifying line items appear in the document, sorted according to your specifications.
Key Limitations to Consider
Before implementing Context Service for document generation, be aware of these constraints:
Context Service Limits
- No OR conditions in filters (AND logic only)
- Reserved words cannot be used as attribute names (Id, BusinessObjectType)
- One filter per template
- Manual migration required between environments
- Server-side only (no client-side generation support)
Data True-Up Limits
- Parent objects only
- DOCX templates only (not PPTX)
- Child objects not supported
Related Resources
Continue your Revenue Cloud document generation journey with these related guides:
- Document Builder Setup – Alternative native solution for quote PDFs
- Custom LWC Sections for Document Builder – Extend Document Builder with custom components
- Pricing Procedures – Uses the same Context Service infrastructure
- Field Mapping in RLM – Context Definition basics for custom fields
- Product to Quote Line Mapping – Custom field mapping series
- Salesforce Contracts – CLM with document generation capabilities
- Revenue Cloud Setup Guide – Complete environment setup
Conclusion
Context Service provides a powerful and flexible approach to document generation in Salesforce Revenue Cloud. By reusing your existing pricing context definitions, you eliminate redundant configuration while gaining access to advanced features like filters and transform plug-ins.
The key steps are: enable document generation, extend your context definition with needed attributes, configure mappings, create filters if needed, build your Screen Flow, and design your Word template with the proper token syntax.
For more complex scenarios like bundle hierarchies or custom grouping, stay tuned for our members-only video on Transform Plug-Ins where we’ll dive deep into Apex-based data transformations.
Have questions about implementing document generation in your Revenue Cloud environment? Drop a comment below!