Loading
Salesforce Document Generation
Table of Contents
Select Filters

          No results
          No results
          Here are some search tips

          Check the spelling of your keywords.
          Use more general search terms.
          Select fewer filters to broaden your search.

          Search all of Salesforce Help
          Create a Hierarchy Transformation for Document Generation

          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.

          Required Editions

          Available in: Lightning Experience
          Available in: Professional, Enterprise, Unlimited, and Developer Editions
          User Permissions Needed
          To configure a hierarchy transformation for Document Generation: DocGen Designer with Admin Persona

          Use Case: A quote contains standalone products, such as monitor and headset, as well as bundle products such as Laptop Pro Bundle that includes items like laptop and mouse. Use hierarchy transformation to show bundle items under their parent product while keeping standalone items separate in the document output.

          Before you begin, make sure that you’ve Set Up Data Transformation for Document Generation.

          1. Create a document template that supports hierarchical data using children or related records.
            This example creates a template for a product quote. You can have up to five levels of nesting.
            Document template with hierarchical data using children and related records.
          2. Create a quote with standalone and bundled quote line items.
            Quote line items showing standalone products and bundle products with pricing and quantity values.
          3. In the Context Definition, add the nodes to define the parent-child relationships in the hierarchy.
            Each node represents a dataset to transform in DPE. In this example, the notes are Quote and Quote Line Item. These nodes later become Data Source Subtype nodes in DPE.
          4. Add relationship fields required for hierarchy.
            The system doesn’t automatically infer hierarchy. These fields explicitly define how records relate to each other. Parent quote line item ID enables self-referencing relationships required for bundle structures.
            1. Quote ID
            2. Parent Quote Line Item ID
              Context Definition showing field mapping for Quote and Quote Line Item, including Parent Reference and identifier fields.
          5. Configure field mapping to identify the parent-child links.
            DPE relies on mapped fields to build relationships. If these fields aren’t mapped, hierarchy construction fails because DPE can’t identify parent-child links.
            1. Map Quote ID to ID
            2. Map Parent Reference to Quote ID
            3. Map QuoteLineItemId to Quote Line Item ID
            4. Map Parent Quote Line Item ID to Parent Quote Line Item ID
              Field mapping for Quote and Quote Line Item showing identifier and parent reference fields.
          6. On the Transform tab, select the transform that you created.
            When you open the DPE definition from the Transform tab, the Data Source node is preconfigured with the context data structure. It uses context as the source type, the selected context definition as the source object. It retrieves context data at run time based on the provided identifier, such as a quote ID.
            The Data Source node and Data Source Subtype nodes are preconfigured and mapped to the context definition to retrieve context data at run time by using the Context Instance Identifier, such as the Quote ID.
          7. Configure the Quote writeback.
            Because Quote is the root object, use a simple JSON structure to make sure that the parent-level data remains flat and acts as the container for the child records.
            1. For Source Node, select Quote.
            2. For Target Type, select JSON.
            3. For JSON Structuree, select Simple,
            4. Enter a JSON name.
            5. Under Field Mapping, map only the required fields.
              Only selected fields are passed to downstream nodes and included in the final JSON output. Including unnecessary fields increases the payload and impacts performance.
          8. Configure Quote Line Item writeback.
            Hierarchy structure is required to represent bundle relationships. Quote Line Item contains self-referencing data, which convert into nested JSON.
            1. For Source Node, select Quote.
            2. For Target Type, select JSON
            3. For JSON Structure, select Hierarchy
            4. Enter a JSON name.
            5. Under Field Mapping, map only the required fields.
            6. To configure the hierarchy configuration, set Parent Identifier to Parent Quote Line Item ID, and Record Identifier to Quote Line Item ID.
              Parent Identifier defines the parent-child relationship, and Record Identifier uniquely identifies each node. Together, they help DPE to construct the hierarchy tree.
          9. Configure Composite Writeback node.
            Composite Writeback combines multiple writebacks into a single structured JSON output. Without it, DPE can’t merge Quote and Quote Line Item data into one hierarchy.
            Composite Writeback configuration showing sequence from Quote to Quote Line Item with parent-child mapping.
            1. Define the sequence as Quote → Quote Line Item.
              The sequence defines the nesting order in the final JSON. Parent objects must appear before child objects.
            2. Map Parent Field to Quote ID
            3. Map Node Field to Parent Reference
              This mapping links child records (Quote Line Items) to their parent (Quote). Without this mapping, child records won’t be attached to the correct parent node.
            4. For Target Type, select JSON.
          10. Save and activate the transformation.
            Hierarchy transformation for the quote example.
          11. Generate a document using the transformation.
            1. In the document template, for Context Transformation Name, select the transformation.
            2. For the input, enter the Quote ID.
              The Quote ID acts as the Context Instance Identifier to retrieve and transform data at run time.
            3. Generate the document.
              Template output with the hierarchy tranformation.
           
          Loading
          Salesforce Help | Article