Generate Document
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.
The Document Generation action requires the following input parameters:
- CloudFiles Variables: Custom runtime variables used during the document generation process.
- 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.
- 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.
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.
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.
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.
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.
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.
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.
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.
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.
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 -