Dev: Object Agnostic PDF Upload

Published on February 10, 2026 DRTE


Generate PDF and Upload to Files (Return Content Version Id)

Use the Generate PDF and Upload to Files, return Content Version Id action (generatePdfAndUploadToFilesDocument) to turn Rich Text content from any Salesforce record into a PDF that is saved to Files and linked to that record.

At a Glance

  • Object-agnostic: works with any field (typically a Rich Text Area) on any Salesforce object.
  • Branding: supports an optional header image and footer text.
  • Output: a ContentVersion record linked directly to the source record.

1. Functional Summary

Unlike the "Directly on Server" action, which targets a temporary Preview record, this method (generatePdfAndUploadToFilesDocument, labeled "Generate PDF and Upload to Files, return Content Version Id") is designed to be object-agnostic. It can target any field (typically a Rich Text Area) on any Salesforce object.

It retrieves the content from the specified field, renders it as a PDF with optional branding (headers/footers), and creates a ContentVersion record linked directly to the source record.

2. Input Parameters

Three parameters are required. The rest are optional and control file naming and PDF branding.

ParameterAPI NameTypeRequiredDescription
Record IDrecordIdTextYesThe ID of the record where the content lives and where the file will be attached.
Object API NameobjectApiNameTextYesThe API name of the target object (e.g., Account, Contract).
Source Field API NamefileApiNameTextYesThe API name of the field containing the HTML/Rich Text content (e.g., Rich_Content__c).
File NamefileNameTextNoThe title of the generated file (omit ".pdf"). Defaults to the Token value.
Envelope TokentokenTextNoA unique identifier used for the filename fallback and PDF metadata.
Footer TextfooterTextTextNoCustom text to render in the footer of the PDF.
Header Image URLheaderImageURLTextNoA public URL for a branding logo to appear in the PDF header.

3. Flow Implementation Guide

Scenario: Converting a "Final Comments" field to a PDF Archive.

  1. Trigger: Create a Record-Triggered Flow that runs when a Case is marked "Closed."
  2. Add Action: Search for "Generate PDF and Upload to Files, return Content Version Id".
  3. Map Variables: Set the action inputs as shown in the table below.
  4. Result: Upon Case closure, a PDF of the resolution summary is automatically generated and attached to the Case.
Action InputValue
Record ID{!$Record.Id}
Object API NameCase
Source Field API NameResolution_Summary__c (a custom Rich Text field)
File NameClosure_Summary_{!$Record.CaseNumber}

Expected Outcome: Each time a Case is closed, the resolution summary is archived as a PDF in Files and linked to that Case automatically.


4. Developer Constraints & Best Practices

Transaction Limits: Because getContentAsPDF() is treated as a callout, you cannot perform any DML (like updating the record) before calling this action in the same transaction.

Best Practice: Place this action at the very beginning of your Flow logic or use a "Pause" element to separate transactions.

Security Error Handling: If the objectApiName is invalid or the user lacks permissions, the method throws an AuraHandledException. In a Flow context, ensure you use Fault Paths to handle these exceptions gracefully.


Knowledge Article Number: KA-00108

View more articles in the knowledge base