Dev: Server-Side Generation
1. Functional Summary
The generateDocumentDirecltyOnServer (Generate Document Directly On Server without Editor) action is the "production" engine of DRTE. It accepts a temporary Preview ID (generated via the assembly service) and performs a server-side conversion into a permanent Salesforce File (ContentVersion).
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 upon a data change.
2. Input Parameters
Parameter | API Name | Type | Required | Description |
Preview ID | previewId | Text | Yes | The ID of the pscdnyrichtext__Rich_Text_Preview__c record containing the HTML to be converted. |
Record ID | recordId | Text | Yes | The ID of the parent record (e.g., Account, Opportunity) where the file will be attached. |
Object API Name | objectApiName | Text | Yes | The API Name of the target parent object (e.g., Custom_Object__c). Used for security validation. |
File Name | fileName | Text | No | The title of the file. Do not include extension. Defaults to token.pdf. |
Envelope Token | token | Text | No | A unique identifier used for tracking and as a fallback filename. |
Footer Text | footerText | Text | No | Injects custom text into the PDF footer region. |
Header Image | headerImageURL | Text | No | Public URL of a logo to render in the PDF header. |
5. Implementation in Flow Builder
Integration Steps
- Generate Preview: Use the generateDocumentService action first to obtain a previewId.
- Invoke Server Action: Add the Generate Document Directly On Server action.
- Map Variables: Use the output from step 1 as the previewId for this step.
- 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.
6. 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.