You are here:
Transform Context Data for Document Generation
A DocGen transformation is how you prepare data before a document is generated. You can reshape flat data into hierarchies, group related records, and derive the values a template should show such as, nesting products under a bundle or calculating totals. The Data Processing Engine (DPE) uses a context definition to run that logic and output structured JSON; document generation then reads that JSON to fill the template. Together, the transformation step closes the gap between source records and a predictable structure for the template.
Required Editions
| Available in: Lightning Experience |
| Available in: Professional, Enterprise, Unlimited, and Developer Editions |
Key Capabilities
- Hierarchy: Represent bundle hierarchies and group relationships by using parent-child structures, supporting up to five levels of nesting. For example, group accessories such as Mouse and Keyboard under a parent product such as laptop.
- Multilevel hierarchy: Build hierarchical structures across related objects, such as Quote → Quote Line Group → Quote Line Item, or across multiple levels, such as Region, Country, and City.
- Grouping: Group records based on attributes or conditions, such as Selling Model Type, to organize data into categorized sections.
- Default values: Apply default values for missing fields, such as image height and width, when they aren’t provided in source data. This ensures consistent rendering in the generated document.
- Formula-based transformation: Calculate derived values by using formulas, such as total price from Quantity and Unit Price, or format values before showing them in the document.
Steps Involved in DocGen Transformation
Complete these steps in a sequence.
- Create a context definition to model your data.
- Select the Is Transform Available checkbox to turn on transformation, and then configure it in the Transform tab.
- Create the DPE definition from the Transform tab. The main node and sub-type nodes are automatically populated based on the context data structure. It is recommended to retain these nodes as is.
- Define transformation logic in the DPE definition, such as hierarchy, grouping, and formulas. This includes configuring Data Source, Data Source Subtype, Formula, Join, and Writeback nodes.
- Create a document template and set the token mapping method to Context Service.
- In the template, select a transformation in the Transformation Name field. Only transformations associated with the selected context definition are available.
- Generate the document. Context Service retrieves data, DPE transforms it, and document generation uses the transformed JSON.
- Set Up Data Transformation for Document Generation
Convert flat data into hierarchical structures, group records, and calculate values by defining the context and configuring the Data Processing Engine (DPE) structure. - Create a Hierarchy Transformation for Document Generation
Use a parent–child transformation to turn source data from records in your org into a hierarchy for document generation, so repeating sections and tables can show parent and child records the way you model relationships in Salesforce. The structure can follow a single object, for example, a parent record and its child records or a chain of related objects and record relationships such as a header and lines, or region and subordinate levels. The document output reflects that hierarchy instead of a flat list of line items or fields. - Create a Multilevel Hierarchy Transformation for Document Generation
Create a nested hierarchy across groups, bundles, and products. - Create a Group by Transformation for Document Generation
Group line items based on selling model type. - Create a Formula-Based Transformation for Document Generation
Calculate derived values such as total price. - JSON Output for Hierarchy Transformation in Document Generation
This sample JSON output represents hierarchical quote and bundle data structured for document generation. - JSON Output for Multilevel Hierarchy Transformation
This sample JSON output represents multilevel hierarchical quote and bundle data structured for document generation. - JSON Output for Group and Bundle Hierarchy Transformation
This sample JSON output represents hierarchical quote data with groups, bundles, and products structured for document generation. - JSON Output Types and Formula Functions for DocGen Transformation
DocGen uses these JSON output types and formula capabilities for transformation. - Sample Context Definitions for Context Transformation in Document Generation
Use these example context definitions to understand how hierarchy, grouping, formulas, and default values structure data before document generation when using Data Processing Engine (DPE). - Considerations for Data Transformation with Data Processing Engine for Document Generation
Understand the requirements and guidelines for configuring transformations by using Data Processing Engine (DPE). Learn how configuration impacts hierarchy, grouping, and calculated data in a generated document. - Considerations for Context Transformation in Document Generation
Keep these considerations in mind when you design templates, configure Data Processing Engine (DPE), and generate documents. These constraints impact how you structure context definitions, transformation logic, and document templates.
Did this article solve your issue?
Let us know so we can improve!

