Generate Document
The CloudFiles: Generate Document flow actions allow you to automate document generation directly within Salesforce Flow Builder. Instead of manually selecting a template and generating documents via the CloudFiles Doc-Gen LWC on a Record Detail page, this action streamlines the process by automating document creation based on specific triggers and criteria defined in your flow.
Below is how the action looks like. Detailed descriptions of the input and output parameters are provided in the following section.
The CloudFiles: Generate Document flow action automates document creation using predefined templates and criteria set within Salesforce Flow Builder.
- Document Generation:
- Creates documents in PDF or DOCX format based on specified parameters.
- Supports dynamic template assignment (e.g., based on record type or decision logic).
- Storage Options:
- Save the generated file in Salesforce by:
- Linking it to a specific record as a content document.
- Placing it in a designated file library.
- Store the file in external storage when using the package with the CloudFiles | Document Management & Sharing Platform
- Dynamic Variables:
- Insert placeholders into templates for dynamic content.
- Assign values to these variables within the flow (e.g., user name, dates).
- PDF Security Features:
- Configure advanced security options for PDFs, such as:
- Allowing/disallowing printing or form field editing.
- Locking the document for edits.
- Setting an owner password or a view password.
Example Use Case:
Automatically generate a contract in PDF or DOCX format from a dynamically assigned template (e.g., based on record type). The contract:
- Includes dynamic variables like the user's name.
- Is locked for edits and protected with an owner password.
- Is saved in a specified location, such as a Salesforce File on the Opportunity record or in the dedicated Opportunity's external storage folder.
This action simplifies document generation while providing flexibility and control over content and security.
Here is a list of all input parameters with a summary. For details, check out the individual sections below:
- CloudFiles Variables: Pass custom runtime variables and edit the fields.
- Destination: Information specifying where the generated template/document will be stored.
- Document Type (docx/pdf): The type of document to be created, either PDF or DOCX.
- Parameters: Parameters for editing the document, such as password protection, locking, or printing permissions.
- Record ID: The record ID of the object for which the document is to be generated, such as “Triggering Account > Account ID”.
- Template: The newly created resource, such as “TemplateId” in the example shown in Document Generation using CloudFiles.
The CloudFiles Variables parameter allows you to input values for custom runtime variables used in templates. This feature supports dynamic document generation by enabling flexible data assignment at runtime.
Steps to Configure CloudFiles Variables Input Parameter
- Create Resources for Runtime Variables:
- Create a new Apex-Defined Variable of the Apex class cldfs_CloudFilesVariable for each runtime variable you want to use.
- Each variable includes two fields:
- Key: The API name of the runtime variable (retrieved from the "Resources" section in the Template Builder).
- ValueString: The value to be assigned to the variable.
- Assign Key-Value Pairs:
- Use an Assignment Element in your flow to populate the runtime variables:
- Set the Key to the API name of the runtime variable from the MS Word, Excel, or PowerPoint template.
- Assign the desired ValueString.
- Build a Collection Variable:
- Create a Collection Variable of the same Apex class (cldfs_CloudFilesVariable).
- Add all the configured individual runtime variables to the Collection Variable.
- Input the Collection in the Action:
- Input the Collection Variable into the CloudFiles: Generate Document action's CloudFiles Variables paramter.
This configuration enables dynamic assignment of variables, ensuring document outputs are flexible and tailored to meet specific requirements. Runtime variables can personalize templates, automate complex workflows, and support highly customized document generation scenarios.
The Destination parameter determines where the generated document will be stored after CloudFiles completes the document generation process.
Steps to Configure Destination:
- Create an Apex-Defined Variable of Apex Class cldfs__Resource
- Assign the necessary metadata (e.g., Library, DriveId, Id) based on the chosen storage option.
- To Save in Salesforce
- Default Behavior (Salesforce Files):
- If no destination parameter is specified, the file is stored in the Salesforce File Library.
- Link to a Specific Record:
- Assign the following fields:
- Library: Set to salesforce.
- Id: Set to the RecordId of the Salesforce record to which the file will be linked.
- To Store in External Storage
- Assign the following fields to define the external storage location:
- Library: Specify the library name.
- DriveId: Specify the ID of the connected drive.
- Id: Specify the ID of the folder or location within the drive.
- Pass the configured variable as the Destination Parameter in the CloudFiles: Generate Document action.
This setup provides flexibility to store files in Salesforce or external storage, aligning with your business needs.
The Document Type parameter specifies the format of the file to be generated based on the chosen template.
- docx:Generates a file using the MS Word Template in .docx format.
- pptx:Generates a file using the MS PowerPoint Template in .pptx format.
- xlsx:Generates a file using the MS Excel Template in .xlsx format.
- pdf:Generates a file in .pdf format, using any MS Word, PowerPoint, or Excel Template.
Select the appropriate type based on your requirements and the template used.
The Record ID parameter specifies the Salesforce record to be used as the data source for generating the document. The document is created based on the data from this record and the predefined template. Provide the Record ID of the object for which the template was designed (e.g., Opportunity, Contact, or Custom Object).
The Parameters input allows you to configure advanced security features for the generated PDF documents.
Steps to Configure:
- Create an Apex-Defined resource of Apex class cldfs_DocGenParamsin the flow.
- In an Assignment element:
- Assign the Variable's fields.
- Set the desired parameters to $GlobalConstant.True or $GlobalConstant.False.
- If no value is set, parameters default to false.
- AllowFillingPdfFormFields: Enables users to fill out form fields in the PDF if the template includes them. ( Options: TRUE or FALSE )
- AllowPdfPrinting: Permits printing of the generated PDF. ( Options: TRUE or FALSE )
- LockPdf: Locks the PDF to prevent any edits.( Options: TRUE or FALSE )
- PdfOwnerPassword: Specifies an owner password to restrict editing access to those with the password. Enter the password as a string value.
- PdfViewPassword: Specifies a view password to restrict viewing access to those with the password. Enter the password as a string value.
Use these parameters to customize the security settings of the generated PDF based on your requirements.
Input the 24-Digit CloudFiles "TemplateId" of a published Template can be found in the CloudFiles App under the Document Generation Tab. This ID is essential for identifying and using the correct template for document generation, ensuring that the documents are formatted and populated as intended based on the specified template.
The CloudFiles: Generate Document action operates asynchronously, meaning it does not provide immediate outputs after execution.
Asynchronous Document Generation: After the action runs, a Document Generated CloudFiles Event is published. There is no direct confirmation or result data immediately available.
How to Verify Document Generation ? Check the specified destination (e.g., Salesforce File Library, record attachment, or external storage) to confirm the document was generated successfully.
Benefits of Asynchronous Design
Trigger Subsequent Flows: Use the Document Generated event to initiate other flows or automate additional actions.
Flexible Automation Architecture: This approach supports handling complex business use cases and enables advanced automation scenarios in Salesforce.
By leveraging this design, you can build scalable and dynamic document generation workflows that align with your organization's needs.
Below is an example of flow created using this flow action -
Error Handling If an action execution fail to generate the document, an Error Event is published for that specific action. These events can be used to identify and handle issues with individual document generation requests.