Tutorials
Document Generation Tutorials
Generate PDF template
in this tutorial, we will learn how to use a fillable pdf form to create a template for automated document generation with template actions in cloudfiles, you can configure the fillable fields of the pdf so they map directly to data from your crm this ensures that information flows automatically into the right fields, eliminating manual entry and maintaining accuracy across all generated documents what to expect by the end of this tutorial, you will learn how to configure a fillable pdf template using actions like insert field and insert condition to map salesforce data publish the template for both manual use (from record pages) and automated use (with salesforce flows or processes) prerequisites install cloudfiles in salesforce cloudfiles is available on the salesforce appexchange and can be installed using the standard app installation process check out installation docid\ aw06gffsiiq qdp1fkgcj and configuration docid\ zgbv7ll pzzzopel4 7up guides to set up your account and user access have a fillable pdf form ready before creating a template, make sure you have a fillable pdf form available a fillable pdf contains input fields such as text boxes and checkboxes that can be mapped to salesforce data getting started with template setup before we start mapping fields, we need to upload the pdf form we want to work with in this tutorial, we’re using the irs w 9 form as an example because it’s a common document businesses require from vendors or organizations for tax purposes we’ll connect this form to the account object in salesforce, since most of the details required on a w 9, such as business name, address, tax classification, and ein are typically stored in account records along with some custom fields this makes accounts the most natural fit for generating w 9s automatically 1 upload a template once uploaded, the template will be ready for configuration, where you can map salesforce fields, add conditions, and prepare it for document generation steps to create a pdf template in salesforce, open the cloudfiles app and go to the document generation tab click upload template and select your irs w 9 pdf enter a template name (e g , “w 9 form – account”) once uploaded, locate it in the list, click the menu icon (⋮), and choose edit in the side panel, set salesforce as the platform select the account object click submit the pdf opens in edit mode, ready for mapping 2 insert field use insert field to place values from salesforce fields into text areas of the pdf map “account name” to “name (line 1)” click the name (line 1) field on the pdf in the right panel, under select action , choose insert field in field , type or select {!$record name} (account → name ) map other fields as below business name (custom field) → business name/disregarded entity (line 2) billing street → address (line 5) billing city → city (line 6) tax id (custom field) → employer identification number (part i) 3 insert condition use insert condition to control checkboxes in the pdf based on salesforce data map “account type = individual” to “individual/sole proprietor” in the edit mode, click the checkbox for individual/sole proprietor in the right panel, under select action , choose insert condition in the condition builder select field → {!$record type} set operator → equals enter value → individual click insert to apply the condition map other fields as below if record type = corporation , tick c corporation if record type = partnership , tick partnership if record type = other , tick other 4 resources (optional) when setting up pdf templates in cloudfiles, you may need to include data beyond the main object (account) this is done using resources docid\ kjx57xyov8lkvj1vpioen , which act as variables during template mapping resources can represent values such as related record details (record single variable) or user provided inputs (runtime variable) record single variable a record single variable docid\ vwhs3pzv6unh2 77nrq7n is used when you need to bring values from a related or different object into your pdf template instead of being limited to the fields on the main object (e g , account), you can extend the template to include data from related records such as contacts, opportunities, or custom objects why use it here? in the w 9 form, the “requester’s name and address (optional)” field is not typically stored on the account record instead, it may come from a related contact (e g , the primary requester) by using a record single variable, you can fetch that contact’s details and map them into the optional field on the pdf steps to create and use a record single variable create the variable go to resources → + create new resource select record single variable set the object as contact give it a label (e g , requester) add filter criteria add a condition account id = {!$record id} this links the contact record to the account being used insert the variable the variable will now appear under record (single) variables map to the pdf click the requester’s name and address (optional) field in the pdf use insert field and choose the variable (e g , requester name) this ensures cross object data like contact details can flow into the w 9 even when the template is tied to accounts (refer record single variable docid\ vwhs3pzv6unh2 77nrq7n for more detailed steps on mapping) runtime variable a runtime variable docid\ axlc5bzdbbimwpkbabj9 stores a value that can be passed from a salesforce flow and generated dynamically during execution using doc generation flow actions docid\ nv27oftdk5ukedfzqpbpq it acts as a placeholder for data provided by the user at runtime, which can then be mapped to a field in the pdf template through apex defined variables why use it here? in the w 9 form, the “other (see instructions)” checkbox under tax classification requires additional clarification text since this description varies (e g , “foreign partnership” or “non profit”), the value can be passed at runtime using a runtime variable and then mapped into the pdf field steps to create runtime variable create the variable go to resources → + create new resource and select runtime variable give it a label (e g , other clarification ) set value type as string insert the variable in the template editor, click the other (see instructions) text field on the pdf use insert field and select the runtime variable (e g , other clarification ) to pass a value for this runtime variable, you need to configure how it will be provided during document generation this is typically done in a salesforce flow by creating an apex defined variable , where the value can be assigned based on user input refer to runtime variable docid\ axlc5bzdbbimwpkbabj9 for detailed instructions on configuring and mapping runtime variables in flow 5 publish after mapping save your template publish it as a new template (or overwrite an existing one) the template is now available for generating w 9s from account records after publishing, the template will appear under the document generation → docgen templates tab usage once the template is published , it becomes available for use in two ways manual usage from the docgen widget the published template will appear in the document generation widget on the related salesforce record (e g , account record) steps to generate manually open the related record (e g , account john doe consulting ) in the cloudfiles docgen widget , locate your published template in the list click generate pdf to create the document once generated, you can download the document copy to salesforce files for attaching directly to the record this method is useful for one off requests , such as when a user needs a form generated immediately automatic usage with template id in flows every template in cloudfiles has a unique template id this id can be used in salesforce flow to trigger document generation automatically using doc generation flow actions docid\ nv27oftdk5ukedfzqpbpq for example when a new account record is created, a w 9 can be generated automatically when a record is updated (e g , stage changes > “onboarded” or “contract signed”), the related pdf template can be generated in the background refer to how to generate a document via automation (record triggered)? docid\ f n6ixvldco8bquh26g8f for automatic document generation with record update