Document Generation with CloudFiles
In this quick start guide, you will learn how to integrate Salesforce data into your document workflow using the CloudFiles Word add-in and CloudFiles Doc Gen LWC. You will discover how to install the CloudFiles Word add-in, create and publish personalized templates, and manually generate documents in your desired format. Additionally, this guide covers automating the document generation process based on specific triggers and attaching the generated documents to Salesforce records, streamlining your document management and improving efficiency.
For more detailed information, visit Document Generation
This article is divided into the following sections -
- Insert CloudFiles Document Generation LWC: Learn how to insert and configure the CloudFiles Document Generation Lightning Web Component (LWC) within your Salesforce environment to enable seamless document generation.
- Install CloudFiles Word Add-in: Follow the steps to install the CloudFiles Word add-in, which allows you to create and manage document templates directly within Microsoft Word.
- Create Template: Discover how to create customized Word templates using the CloudFiles word add-in, leveraging Salesforce data to personalize your documents.
- Publish Template: Understand the process of publishing your Word templates within Salesforce, making them available for document generation.
- Generate Documents: Learn how to manually generate documents using your published templates.
- Automate Document Generation: Explore the process of automating the document generation using CloudFiles flow actions & attaching the generated documents to desired salesforce record.
Let's look into each section one by one -
The CloudFiles Document Generation Lightning Web Component (LWC) can be seamlessly integrated into any object's record detail page within Salesforce. Once incorporated, this widget will showcase all the published templates relevant to that specific object. Users have the flexibility to generate documents in either DOCX or PDF formats, which will be automatically downloaded upon creation, simplifying the document management process.
To add the CloudFiles Doc Gen widget to a page, navigate to the record detail page of any object and click the “Edit Page” button. This will open the Lightning Builder for the page. Within the builder, you can easily drag and drop the "CloudFiles Doc Gen" widget into your desired location. After positioning the widget, save and exit the builder, then refresh the Salesforce record page. The widget will now display all the published templates associated with that object, making document generation more efficient and accessible.
For visual understanding, refer to the video below -
The CloudFiles Word add-in facilitates the integration of CloudFiles with your Salesforce Org, enabling you to create and design templates that incorporate Salesforce fields. This powerful tool streamlines the process of merging Salesforce data into documents, making it easier to generate consistent and accurate templates directly from Microsoft Word.
To add the CloudFiles Word add-in to your Microsoft Word application, start by launching Microsoft Word on your PC. Navigate to the "Home" tab and click on "Add-ins" to explore available options. In the Add-ins window, select "+ More Add-ins" to open the "Office Add-ins" window, then click on "Microsoft AppSource" to be redirected to appsource.microsoft.com. In the search bar, type "CloudFiles" and browse the results to locate the CloudFiles Add-in. Click "Get it now" to install the add-in. Once the installation is complete, open Word to check the new add-in. In the "New Office Add-in" sidebar, click "Allow and Continue" to launch the CloudFiles Word add-in, ensuring it's ready for use with your Salesforce data.
Refer to the video below to have a visual understanding of these steps -
You can create a template for any Salesforce object you want. Using various actions, you can insert object fields, related data, and custom resources. Additionally, you can add pictures, tables, and set conditions for content insertion, as well as specify the title of the generated documents. During the template creation process, you can utilize resources to retrieve data from the connected Salesforce Org and design the template with these resources using actions.
Once the CloudFiles Word Add-in is installed and the Salesforce Org is connected, you can start building a template for a selected object. To get started, you must select your primary resource, i.e., the Master Object for which you wish to build the template. In the CloudFiles Add-in sidebar, select Salesforce as the platform and the Salesforce Object as the Master Resource. After clicking 'Submit,' you will be directed to the next stage of selecting actions and utilizing resources.
Refer to the GIF below to have a visual understanding of this process -
After building a template and reviewing it, the final step is to publish the template. Publishing makes the template available in your Salesforce Org for document generation on the specified object. To begin, navigate to the 'Publish' stage by clicking on 'Publish' in the 'Stage Progress Bar'. You will then need to choose your publishing option: either check the 'Publish as a New Template' checkbox to publish it as a new template for the object, or check the 'Select an existing template' checkbox and choose an existing template from the drop-down to update an existing one.
Once you've made your selection, click 'Publish'. A pop-up message confirming 'Successfully Created a Template' will appear, indicating the template has been created. To verify the template, you can check the newly created or updated template from the 'CloudFiles Doc-Gen' widget on the object's page or from the 'Document Generation' tab of the CloudFiles app.
Refer to the GIF to have a visual understanding of the steps above -
Once the CloudFiles Doc Gen LWC is added to the record page and the template has been published, you can start generating documents in either DOCX or PDF format, which will be automatically downloaded upon generation.
To manually generate a document from CloudFiles Doc Gen LWC, navigate to the 'CloudFiles Doc Gen LWC' on any object page. Click the drop-down menu next to the template you want to use and select either 'Generate DOCX' or 'Generate PDF' for the desired document format. The document generation process takes a moment. Once completed, you can either download the generated document or choose 'Copy to Salesforce Files' to upload it as a Salesforce File, attaching it to the record in the 'Files' section.
Refer to the video below to have a visual understanding of this step -
You can automate document generation using Salesforce Flow Builder and CloudFiles actions based on specific triggers and criteria. Below, we'll create two flows: one to automate document generation using Flow Action and another to ensure the generated documents are properly attached to the corresponding Salesforce records. This is how the automation looks like -
The flows are discussed in brief below -
Create a new flow type that suits your needs, such as a Record-Triggered Flow. Add the 'CloudFiles: Generate Document' action to the flow and configure the action by entering the following parameters:
- Format: Choose a format (DOCX or PDF).
- Template ID: Enter the Template ID (found in the 'Document Generation' tab).
- Record ID: Enter the object's record ID for which the document is to be generated.
- User ID: Enter the CloudFiles System User's ID (the user used to set up CloudFiles in the Salesforce Org).
Save and activate the flow. When the flow's trigger conditions are met, the action will automatically generate a document and create a Content Version in Salesforce.
Refer the video below to have a visual understanding of these steps -
A CloudFiles Event of type document-generated is published upon document generation. The generated documents can be handled further through a Platform Event-Triggerred Flow given below -
Create a new platform-triggered flow and choose Platform Event as 'CloudFiles Event'. Configure the flow to handle the generated documents by following these steps:
1 - Add a Decision Element: Add a 'Decision' element to the flow to identify when a document is generated.
- Resource: $Record > Type
- Operator: "Equals"
- Value: document-generated
2 - Get Event Details: Add a 'Get Event Details' action. Set the input value for the 'Event' parameter as {!$Record}.
3 - Check Object Type: Add a 'Decision' element to check the object type on which the document is generated. Set the condition to identify the object type as
- Resource - Outputs from Get_Event_Details > DocumentGenerated > ParentId
- Operator - "Starts With"
- Value - Object ID identifier i.e., record ID's first 3 digits. For Account Record it is 001
4 - Get Content Version: Add a 'Get Records' element to get the 'Content Version' record of the generated document. Identify the record by ID using outputs from Get_Event_Details > DocumentGenerated > ContentVersionId.
5 - Attach the Generated Document to the Record: Add a 'Create Records' element to create 'Content Document Link'. Set the field values as -
- LinkedEntityId: Outputs from Get_Event_Details > DocumentGenerated > ParentId
- ContentDocumentId: Content Version from Get_generated_document_s_Content_Version > ContentDocument ID
Save and activate the flow. This will ensure the generated document is attached to the record as a Salesforce File in the 'Files' section. This is how the final flow looks like -
Refer to the GIF below to have a visual understanding of these steps -
To sum up, by following this guide, you can install the CloudFiles Word add-in, create and publish personalized templates, and automate document generation based on specific triggers. Additionally, it covers automating the attachment of generated documents to Salesforce records, streamlining your document management and improving efficiency.