Dev: Generate HTML String

Published on February 10, 2026 DRTE


Build Document and Return HTML String (generateHTMLService)

The generateHTMLService method (Build Document and return html string) invokes the core DRTE assembly engine to merge Salesforce data into a template and returns the result as a raw HTML String.

Stateless by design. Unlike generateDocumentService (Build Document and return Preview Id), which saves a Preview Record and returns its ID, this method creates no record. It returns the output immediately as a string.

1. Functional Summary

Because the merged document is returned as a string, this method is ideal for:

  1. Populating the body of an Email Alert.
  2. Sending document content to an external API or middleware.
  3. Displaying content in a standard Flow "Display Text" component.

2. Input Parameters

ParameterAPI NameTypeRequiredDescription
Parent Record IDparentRecordIdIDYesThe ID of the record used as the data context (e.g., Account, Opportunity).
Template IDdocumentTemplateIdIDYesThe ID of the pscdnyrichtext__PSC_Document_Template__c (DRTE) record to be processed.

3. Output Values

ParameterData TypeDescription
HTML ContentText (String)The complete, merged HTML string generated from all active template sections.

4. Architectural Comparison: Preview ID vs. Raw HTML

Choosing the right method is critical for performance and scalability:

FeatureReturn Preview IDReturn HTML String
PersistenceCreates a temporary record in the database.No record created; string exists only in memory.
UI InteractionBest for use with the DRTE Editor LWC.Best for automated emails or external calls.
Data SizeHandles very large documents easily.Subject to Salesforce Flow string length limits.
CleanupRequires eventual deletion of Preview record.No cleanup required.

5. Flow Implementation Guide

Scenario: Automated "Thank You" email with an order summary.

  1. Trigger: A Flow runs when an Order is "Activated."
  2. Add Action: Search for "Build Document and return html string".
  3. Map Variables:
  4. parentRecordId: {!$Record.Id}
  5. documentTemplateId: Your specific Summary Template ID.
  6. Store Result: Assign the output to a text variable, e.g., varEmailBody.
  7. Send Email: Use the standard Send Email action in Flow. Set the body to {!varEmailBody} and ensure Rich Text Templating is enabled on the email action.
Result: When the Order is activated, the customer receives an email whose body is the fully merged template, with no Preview record to clean up.

6. Developer Considerations & Limits

String LimitsSalesforce Flow variables can hold large amounts of text, but be cautious of the 32,768 character limit for certain standard "Long Text Area" fields if you plan on mapping this string back to a field. For extremely large documents (e.g., 50+ page legal contracts), the Preview ID method is safer.
BulkificationThis method processes the first item in the input list (Ids[0]). When using it in a loop within a Flow, ensure you do not hit the SOQL limit, as each call triggers a query for the template sections.
CSS StylesAny CSS defined in the template sections is returned inline or within style tags in the string. Some email clients (like Outlook) have limited support for advanced CSS.

Knowledge Article Number: KA-00105

View more articles in the knowledge base