January 20, 2026

How to Use Context Service for Document Generation in Salesforce Revenue Cloud

Jean-Michel Tremblay

Salesforce Consultant

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

Start Learning Now

Sign up now for the Revenue Cloud Training and Save 10%

Start Learning Revenue Cloud

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

BenefitDescription
Reuse Pricing ContextThe same SalesTransactionContext used by pricing procedures works for document generation
Rich Content SupportImages, hyperlinks, rich text, and Data True-Up tokens are all supported
Multiple TemplatesOne context definition can support templates for Quotes, Orders, and Contracts
Repeating ContentLine items automatically loop using repeating content tokens
Related Object DataPull tokens from related objects like Quote.Account.Name
Filter SupportContext 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:

  1. Context Definition – Defines the nodes and attributes (your data structure)
  2. Context Mapping – Links that structure to actual Salesforce fields
  3. Document Template – Your Word or PowerPoint file with tokens
  4. Context Filter (Optional) – Filters, sorts, or limits records
  5. Transform Plug-In (Optional) – Custom Apex for hierarchies and grouping
  6. 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

OptionPurpose
Design Document TemplatesEnables the template designer within Salesforce
Salesforce Contracts ConnectorMicrosoft 365 Word integration for CLM
Document Templates ExportMetadata/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.

FieldValueNotes
LabelDocGenYour preferred name
Template LibraryDocgenDocumentTemplateLibraryAuto-Created Library
Generation MechanismServer-SideRequired for Context Service
Preview TypePDFPDF 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:

  1. Open your context definition and click Edit
  2. Navigate to the Sales Transaction node
  3. Click Add Attribute
  4. Configure the new attribute:
    • Name: AccountName
    • Type: Input and Output
    • Data Type: String
  5. Add a corresponding Tag with the same name
  6. 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.

To map the AccountName attribute to the related Account’s Name field:

  1. Click Edit Mapping
  2. Find your new attribute under Unmapped
  3. On the right panel, navigate through the relationship: Quote → Account ID → Name
  4. Select the field and click Save
  5. Click Save and Publish to activate the mapping
AttributeSalesforce Field Path
AccountNameQuote.Account.Name
TotalPriceQuote.TotalPrice
BillingCityQuote.BillingCity
ProductNameQuoteLineItem.Product2.Name

Token Naming Conventions

Context Service uses special prefixes for different content types. Understanding these conventions is essential for building effective templates.

Token TypeFormatExample
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 ID
  • IMG_Logo_height – Optional height
  • IMG_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:

  1. Create a table with your column headers in the first row
  2. In the data row, place {{#SalesTransactionItem}} before the first cell content
  3. Add your field tokens in each cell
  4. 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

  1. Click New Filter
  2. Enter a name (e.g., “QuoteLineFilter”)
  3. Add conditions:
    • Node: SalesTransactionItem
    • Attribute: Quantity
    • Operator: Greater than or equal
    • Value: 5
  4. Configure sort order:
    • Attribute: Quantity
    • Direction: Ascending
  5. Set record limit (e.g., 10)
  6. 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 FilterTransform Plug-In
Filter out unwanted recordsGroup by category
Sort recordsBuild hierarchies (bundles)
Limit Record CountCustom Calculations
No Code RequiredRequires Apex
AND Logic onlyFull 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.

Start Learning Revenue Cloud

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:

  1. Let users select a template
  2. Create a DocumentGenerationProcess record
  3. 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:

FieldValue
DocGenAdditionalInput{!recordId.Id}
DocGenAdditionalInputTypeContextService
DocumentInputTypeDocumentTemplate
DocumentTemplateId{!QuoteTemplateId}
ReferenceObject{!recordId.Id}
RequestText{!RequestTextFormula}
StatusInProgress
TypeGenerateAndConvert

Add Flow to Quote Page

  1. Edit your Quote Lightning Record Page
  2. Add a Flow component
  3. Select your document generation flow
  4. Check “Pass all field values from the record to the flow”
  5. 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

  1. Navigate to App Launcher → Design Document Template
  2. Click New
  3. 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
  4. Upload your Word file
  5. Click Save and Activate

Testing Your Document Generation

With everything configured, test the complete flow:

  1. Navigate to a Quote with line items
  2. Open the Document Generation tab
  3. Select your template
  4. Click Next to generate
  5. 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

Continue your Revenue Cloud document generation journey with these related guides:

Start Learning Now

Sign up now for the Revenue Cloud Training and Save 10%

Start Learning Revenue Cloud

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!

Leave a Comment

Free Assessment