Tutorials
Document Generation Tutorials
How to build a template (Word)
this guide explains how to create a template using cloudfiles document generation the cloudfiles add in feature allows you to build templates in microsoft word (docx) using salesforce data for this tutorial, we will use the order object to create a sample purchase order template you will learn how to use the insert field , insert image , insert table , and insert condition actions to generate documents with data from salesforce records what to expect by the end of this tutorial, you will know how to create a docx template with fields mapped from salesforce insert text, image, and table elements into a docx template use conditions to show or hide content based on logic preview and publishing document to salesforce tutorial video refer to the quick video if you would like to have a visual guide for this tutorial read on if you prefer textual content video will be added soon 1 pre requisites install cloudfiles in salesforce cloudfiles document generation app is available on the salesforce appexchange and can be installed using the standard app installation process check out installation guide docid\ fv1sn qekhvsae njyp6y to know more template builder setup the cloudfiles add in connects with your salesforce org to enable template creation using salesforce data it can be installed in microsoft word, excel, or powerpoint, allowing you to design templates directly for installation steps, see template builder setup docid\ ez 0n5yay5b5sofv4 fbf 2 stages of document generation document generation includes 3 main stages build preview publish after logging in to salesforce through the cloudfiles add in, set salesforce as the platform and select the order object in this tutorial, we will use the order object to create a sample purchase order template why use a purchase order template? a purchase order is a common document used to confirm and track product or service purchases it generally includes the order number, account information, shipping and billing details, and a list of items in this tutorial, we use the order object in salesforce, which contains all the required details for generating the document for item level information, we use the orderitem object, which holds product names, quantities, prices, and totals used to populate tables in the template we have created a sample purchase order template with placeholder fields for reference (see screenshot below) in the build stage, we will show how to use each action insert field , insert image , insert table , insert link, and insert condition , to replace those placeholders with actual merge fields from salesforce after installing the cloudfiles add in and setting up salesforce, you can use the template actions to insert fields and tables from salesforce data into the document stage 1 build global variable by default, the template stores $record with the selected salesforce record (in this case, the order object) this variable refers to the record you are working with using this reference, you can insert fields like ordernumber, effectivedate , and related account fields into your template insert field use the insert field docid\ xuxxbf3cnqkevpq qglsy action to add fields from salesforce records into your template you can include both text and numeric fields place the cursor where you want to insert the field, then select insert field from the action menu choose the $record variable, then select the required field and click insert insert the following fields into the purchase order template orderdate – {{!$record effectivedate}} orderno – {{!$record ordernumber}} accname – {{!$record account name}} billingstreet – {{!$record account billingstreet}} you can similarly insert other fields such as billingcity , shippingstreet , shippingcity , etc additionally, you can insert fields from other related object records, such as contract, by creating a record single variable docid\ vwhs3pzv6unh2 77nrq7n resource and then using template actions to reference and insert those fields into your document note ensure that the integration user has the necessary permissions to access the fields being inserted if the required access is missing, the fields will not be available for use in the template insert picture use insert picture docid\ ecjlal qa4eh1op78bkkh action to add an image to the template this is ideally used for company logos, product images, etc place the cursor where the image should appear in the document, then select the insert picture action choose a field that contains a valid image url, such as a logo url stored in the account record you can also adjust the size of the image in the purchase order template, insert the custom field company logo c from the account object, which holds the image url image {!$record account company logo c} insert link use insert link docid\ zocdzjfdwqe2mow2dqzeb to add clickable urls from salesforce fields into your template in the purchase order template, insert the field website from the account object, which holds the url of the website website – {{$record account website}} this will generate a working hyperlink in the final generated document insert table use insert table docid\ wrbkuy wz6avv0z sizgl action to include repeatable rows for lists, such as line items or products before adding a table, create a record collection variable docid\ d4biogeef7uoj7eiznung with object set to ' order product ' which is typically used to represent the line items associated with the order (e g , products purchased, quantities, and pricing)and add filter criteria as below order id equals {!$record id} now, the record collection orderitems contains the products of the order to configure the table, follow the steps below place the cursor on the template and select the insert table action in the resource type field, select the collection orderitems you created specify the required number of columns and rows add column labels for item , quantity , unit price , and subtotal in the first row place the cursor on the second row and use the cloudfiles add in , then click ‘make data row’ to include the values of the collection insert the following fields into the table from the collection orderitems using the insert field action product name {!order items product2 name} quantity {!order items quantity} unit price {!order items unitprice} total price {!order items totalprice} you can insert multiple fields into the same cell make sure you insert all the collection fields inside the data row insert condition use insert condition docid\ mznwe55hp3sg 1k6fxylc to show or hide sections based on values from your record in the purchase order template, let's display a message only when the total order amount exceeds $10,000 steps to insert a condition place the cursor where you want the conditional content to appear open the cloudfiles add in and choose insert condition in the field dropdown, select the relevant field (e g , totalamount or order total) set the operator (e g , greater than) and enter the value (e g , 10000) click insert add the message inside < if > to display if the condition is met global constants global constants are predefined values that remain the same for every document by default, the template includes $globalconstant emptystring – blank text value $globalconstant false – boolean false $globalconstant true – boolean true these constants can be used to add fixed values or control logic document title use document title docid\ wdj0rsgp2 miidliectq action to define the name for your generated document this title will be automatically applied when the document is generated you can use values from records and other resources to create dynamic file names in the template, we have used {!$record ordernumber} to set the document title dynamically based on the order number if no document title is specified, the document will default to the name of the template stage 2 preview the preview feature allows you to test how your document will look using real data before publishing it how it works enter a valid record id (e g , a salesforce order id) into the input box click generate preview cloudfiles will populate the template with actual values from the record, showing you exactly how the final document will appear errors at preview in the preview section, if the template has any issues, you may encounter errors, such as 'preview generation failed,' along with a description of the error these errors typically indicate problems like malformed queries, etc make sure to review the error message and correct the issue accordingly before publishing stage 3 publish once you’ve finished building and previewing your template, use the publish step to save it for use in your salesforce org publishing options ✅ 1 publish as a new template choose this if you're creating a template from scratch enter a unique template name in the input field this will create a new version that will be available for use 🔄 2 select an existing template choose this option to update or replace a previously published template select from the list of available templates in the dropdown your current design will overwrite the selected template with the new version once published, the template will be listed under the document generation tab → docgen templates the template id can be used in flow automation to generate documents using the following flow actions generate document docid\ qfdwhv81mxgwsly7nppsc , generate document (sync) docid 9davjkiyvj2zfhjw7zcvx , generate document (batch) docid\ xahb umkpvgfm3k4ycbdp