Dev: Generate HTML String

1. Functional Summary

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

Unlike the generateDocumentService (Build Document and return Preview Id)(which saves a Preview Record and returns an ID), this method is stateless. It provides the immediate string output, making it ideal for:




2. Input Parameters

Parameter

API Name

Type

Required

Description

Parent Record ID

parentRecordId

ID

Yes

The ID of the record used as the data context (e.g., Account, Opportunity).

Template ID

documentTemplateId

ID

Yes

The ID of the pscdnyrichtext__PSC_Document_Template__c (DRTE) record to be processed.



3. Output Values

Parameter

Data Type

Description

HTML Content

Text (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:

Feature

Return Preview ID

Return HTML String

Persistence

Creates a temporary record in the database.

No record created; string exists only in memory.

UI Interaction

Best for use with the DRTE Editor LWC.

Best for automated emails or external calls.

Data Size

Handles very large documents easily.

Subject to Salesforce Flow string length limits.

Cleanup

Requires eventual deletion of Preview record.

No cleanup required.




5. Flow Implementation Guide

Scenario: Automated "Thank You" Email with 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: * parentRecordId: {!$Record.Id}
  1. Store Result: Assign the output to a text variable, e.g., varEmailBody.
  2. 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.


6. Developer Considerations & Limits

CSS Styles: Any CSS defined in the template sections will be returned inline or within style tags in the string. Note that some email clients (like Outlook) have limited support for advanced CSS.

Redirecting you to the article... Click here if you are not redirected automatically.