Tutorials
Document Generation Tutorials
How to build a template (PDF)
in this tutorial, you’ll learn how to turn a fillable pdf form into a reusable template for automated document generation in salesforce by mapping pdf fields to salesforce data, cloudfiles docgen ensures that information flows automatically into the right places, eliminating manual entry and reducing errors 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 docid\ orfoyrd5cikhqt8gizahd and insert condition docid 4rtfqefk4uvthpvsxmy2y 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 to build a template in cloudfiles, you’ll need a fillable pdf form a fillable pdf is not just a static document — it’s a pdf that has interactive fields such as text boxes, checkboxes, and radio buttons layered on top of the form design these fields can capture or display values, which makes them perfect for mapping to salesforce data during document generation common examples of fillable pdfs include government forms (e g , w 9, i 9, tax forms) application forms (e g , bank loans, vendor onboarding) standard business contracts with input fields if your pdf doesn’t already contain fillable fields, you can add them using tools like adobe acrobat (prepare form) or other pdf form editors before uploading it to cloudfiles getting started with template setup for this tutorial, we’ll use the irs w 9 form as an example the w 9 is widely used by businesses to collect tax related information from vendors or organizations 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 steps to upload a pdf form 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 will now open 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 use resources (optional) sometimes you’ll need data beyond the main object (account) template resources docid\ sx1 c9ittouclsjwhf4zw let you pull in values from related records (using a record single variable docid\ vwhs3pzv6unh2 77nrq7n )or capture user provided inputs (using a runtime variable docid\ axlc5bzdbbimwpkbabj9 ) 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 shall now be 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