Skip to content

Generate a Document in Flow Builder

Documents can be generated within flows using an Action element.

  • Drag and drop a flow “Action” onto the flow canvas
  • Select the “Document” category
  • Select the “Generate Document” action

This will appear if the image fails to load

There are several configurable options for generating a document (see complete settings below), but 2 input variables are required:

  1. Record ID - An input value passed into the flow.
  2. Template ID - A ContentVersion record ID of a Word doc merge template.

Record ID

The Record ID is typically passed into a screen flow from the record page layout. For auto-launched flows, the Record ID can be any Salesforce record to be merged with a document template.

This will appear if the image fails to load

Template ID

The Template ID is a reference to a ContentVersion file record that meets the following criteria

  • Title = the title of the file template
  • IsLatest = {$GlobalConstant.True}

The template must be a Word document merge template previously updated with tags mapped to merge fields. See the “Word Document Templates” documentation for details.

This will appear if the image fails to load

Optional Input Values

InputValid ValuesDefault ValueDescription
Attach AsFile or AttachmentAttachmentDetermines if the generated document is attached as a legacy Attachment or Chatter File
Attach As New VersionTrue or FalseFalseFor AttachAs “Files”, indicates that subsequent generations of the same record/template create a new File version. Matched based on file name.
Content MIME Typeapplication/pdf and application/vnd. openxmlformats-officedocument. wordprocessingml.documentapplication/pdfThis value is auto-set based on the File Format input.
File NameText(255)GeneratedDocument.pdfThe Attachment Name or ContentVersion Title property.
File DescriptionText(255)emptyA description associated with the file
File FormatPDF or WORDPDFDetermines the file format for generated document.
Parent IDAny 15 or 18 char record IDRecord IDAllows the generated document to be attached to a record other than the merge RecordID. Example: Merging a Contact record but attaching to parent Account record.
Run AsynchronousTrue or FalseFalseDetermines if the action is executed in a @future method context. Because this action makes an API callout, any uncommitted DML may throw an exception. Set Run Asynchronous=True to avoid this type of error.

Output Values

All document and room actions reflect back the input values to the output and additionally provide a boolean Success value and a Message value. It’s generally best practice to capture these 2 values in variables, particularly in screen flows, for use in providing the user feedback.

OutputValuesDescription
Attachment IDAttachment ID or ContentVersion IDDepending on the file format input, provides a reference to the document that was generated. This value is commonly mapped to a flowe variable for use in downstream activities, like sending the document via email
SuccessTrue or FalseIndicates whether the document generation action was successful. If False then details of the error are available in the Message output value.
Messagenull or String valuePopulated with error message details when Success=False.