Dev: Server-Side Generation

Published on February 10, 2026 DRTE


Generate Document Directly On Server (Without Editor)

The generateDocumentDirecltyOnServer action (Generate Document Directly On Server without Editor) is the "production" engine of DRTE. It converts a temporary Preview ID into a permanent Salesforce File (ContentVersion), entirely on the server.

At a glance: This method is "headless", meaning it requires no UI components. It is best suited for background automation, scheduled jobs, or record-triggered flows where a document must be archived or sent immediately after a data change.

1. Functional Summary

The action accepts a temporary Preview ID (generated via the assembly service) and performs a server-side conversion into a permanent Salesforce File (ContentVersion) attached to a parent record of your choice.

2. Input Parameters

ParameterAPI NameTypeRequiredDescription
Preview IDpreviewIdTextYesThe ID of the pscdnyrichtext__Rich_Text_Preview__c record containing the HTML to be converted.
Record IDrecordIdTextYesThe ID of the parent record (e.g., Account, Opportunity) where the file will be attached.
Object API NameobjectApiNameTextYesThe API Name of the target parent object (e.g., Custom_Object__c). Used for security validation.
File NamefileNameTextNoThe title of the file. Do not include the extension. Defaults to token.pdf.
Envelope TokentokenTextNoA unique identifier used for tracking and as a fallback filename.
Footer TextfooterTextTextNoInjects custom text into the PDF footer region.
Header ImageheaderImageURLTextNoPublic URL of a logo to render in the PDF header.

3. Implementation in Flow Builder

Follow these steps to add the action to a flow:

  1. Generate Preview: Use the generateDocumentService action first to obtain a previewId.
  2. Invoke Server Action: Add the Generate Document Directly On Server action.
  3. Map Variables: Use the output from step 1 as the previewId for this step.
  4. Handle Output: Assign the returned string to a variable.
Success: The variable contains the 068... ContentVersion ID.
Failure: The variable contains a string starting with "Error:". Use a Decision element to check for this.

4. Governor Limits & Constraints

Callout Limits: Since getContentAsPDF() is a callout-like operation, this method cannot be called after any DML (Insert/Update) has occurred in the same transaction.

Solution: Use a "Pause" element in Flow, or an @future / Queueable method in Apex, to reset the transaction before calling this action.
Heap Size: Large documents with many images may approach the 6MB/12MB synchronous heap limit.

Knowledge Article Number: KA-00107

View more articles in the knowledge base