Flow Actions

Generate Document

Introduction

The Generate Document Flow Actions can be used in Salesforce Flow Builder to automate the document generation process. This method streamlines the workflow, ensuring documents are generated based on specific triggers and criteria set within the flow. Below is how the action looks like. Detailed descriptions of the input and output parameters are provided in the following section.





Document image


The Document Generation action requires the following input parameters:

  1. CloudFiles Variables: Custom runtime variables used during the document generation process.
  2. Destination: Information specifying where the generated template/document will be stored.
  3. Document Type (docx/pdf): The type of document to be created, either PDF or DOCX.
  4. Parameters: Parameters for editing the document, such as password protection, locking, or printing permissions.
  5. Record ID: The record ID of the object for which the document is to be generated.
  6. Template: The resource containing the Template ID created by the user.

This action automates the document generation process and does not return a value.

In this article we will dive into the details of the input & output parameters.

What This Action Does

The Document Generation action automates the creation of documents based on predefined templates and specific criteria set within the Salesforce Flow Builder. This action streamlines the process by generating documents in either PDF or DOCX format according to the parameters provided. For instance, it can be used to automatically generate and store a contract in a specified location whenever a new opportunity is closed.

Input Parameters

Here is a list of all input parameters with a summary. For details, check out the individual sections below:

  1. CloudFiles Variables: Pass custom runtime variables and edit the fields.
  2. Destination: Information specifying where the generated template/document will be stored.
  3. Document Type (docx/pdf): The type of document to be created, either PDF or DOCX.
  4. Parameters: Parameters for editing the document, such as password protection, locking, or printing permissions.
  5. Record ID: The record ID of the object for which the document is to be generated, such as “Triggering Account > Account ID”.
  6. Template: The newly created resource, such as “TemplateId” in the example shown in Document Generation using CloudFiles.

Cloudfiles Variables

CloudFiles Variables are used to pass custom runtime variables in the template as needed. To define the parameters for document generation in CloudFiles, start by creating a new resource named "runtime variable." Set the data type to Apex-Defined and specify the Apex class as cldfs_CloudFilesVariable. Next, create a collection variable, ensuring the "Allow multiple values (collection)" option is selected.

Once these resources are in place, create an assignment element in your flow. Add the newly created "runtime variable" resource to this assignment element, setting the key equal to the API name of the runtime variable defined in the resources section of the MS Word add-in. Then, define the valuestring for this runtime variable and add it to the collection variable created earlier.

Finally, include the collection variable in the CloudFiles: Generate Document action. This configuration allows for the dynamic assignment of variables, making the document generation process more flexible and efficient. By incorporating these runtime variables, document outputs can be tailored to meet specific requirements.

Document image


Destination

The Destination information specifies where the template/document will be stored. To achieve this, create an assignment element in your flow. Add the newly created resource named "destination_info" and assign it the following properties:

  • destination_info > library
  • destination_info > drive ID
  • destination_info > folder ID

Set these properties to the corresponding values obtained from the view metadata in the Content Library. This ensures that the destination information is accurately configured based on the metadata retrieved from the Content Library, allowing the template/document to be correctly stored in the specified location.

Document image


Document Type (docx / pptx / pdf)

Choose the type of document to create: DOCX, PPTX, or PDF. This selection tailors the output format to specific needs, ensuring compatibility and ease of use for various applications.

Record ID

The Record ID is crucial as it specifies the exact account record in Salesforce that initiates the flow or automation when an event is triggered (either created or updated). When the automation is triggered, this Record ID ensures that all related resources and actions are accurately associated with the correct account, thereby maintaining the integrity of the document generation or other automated processes depending on your flow actions.

Parameters

To define these parameters, initiate an assignment action and include the newly created resource. Set the data type to Apex-Defined and specify the Apex class as cldfs_DocGenParams. Use these parameters within the assignment element, setting them to either $GlobalConstant.True or $GlobalConstant.False based on the user's requirements. Ensure that you configure the parameter appropriately, setting it to true as needed; otherwise, it defaults to false.

Note - that this configuration is applicable only for documents with the type set to PDF. This approach ensures that the parameters are accurately defined and utilized within the automated workflow for PDF document generation.

  • AllowFillingPdfFormFields: Allows entering details in specific fields.
  • AllowPdfPrinting: Allows printing the PDF.
  • LockPdf: Prevents any changes to the PDF.
  • PdfOwnerPassword: Allows changing the password.
  • PdfViewPassword: Allows viewing the password.

Template

Select the newly created resource, such as "TemplateId." This resource is created to store and manage the template ID, which is received after publishing the template created using the MS Word add-in. The template ID can be found in the CloudFiles application 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. Creating this resource helps streamline the process of referencing and using the template within your automated workflows.

Document image


Output Parameters

Notably, the document generation process does not return any output or provide feedback once the templates are created. This means that after the automation runs and the templates are generated, there will be no direct confirmation or result data provided to the user. To verify the successful creation of documents, users will need to check the specified destination mentioned in the steps above.

Below is an example of flow created using this flow action -

Document image