Dev: Generate Preview ID
1. Overview
The generateDocumentService (Build Document and return Preview Id) is a high-performance Invocable Method that serves as the entry point for the DRTE assembly engine. It performs a "Just-In-Time" merge of Salesforce data into a structured template.
Instead of generating a permanent file immediately, this method creates a temporary HTML Preview record. This allows users to review, edit, or adjust the document content within the Salesforce UI before committing to a final PDF or e-signature request.
2. Input & Output Interface
Input Variables
The method expects a list of the input wrapper. In a Flow context, you provide these as single variables, and Salesforce handles the collection wrapping.
Variable | API Name | Type | Required | Description |
Parent Record ID | parentRecordId | ID | Yes | The context record (e.g., Account, Case) used to filter SOQL data via {pv0}. |
Template ID | documentTemplateId | ID | Yes | The ID of the pscdnyrichtext__PSC_Document_Template__c record defining the structure. |
Output Value
Type | Description |
String (List) | The 18 or 15 -character Salesforce ID of the generated pscdnyrichtext__Rich_Text_Preview__c record. |
4. Flow Implementation Guide
Scenario: "Preview & Edit" Button
To allow a user to preview a contract before sending, follow this Flow pattern:
- Get IDs: Use a Screen Flow to capture the current recordId.
- Call Action: Add the "Build Document and return Preview Id" action.
- Set parentRecordId to {!recordId}.
- Set documentTemplateId to your specific Template ID.
- Store Output: Map the result to a text variable, e.g., varPreviewId.
- Display Screen: Add a Screen element containing the DRTE Editor LWC.
- Pass varPreviewId into the component's recordId property.
- This allows the user to see the assembled data and make manual edits.