Step-by-Step Guide to Generate Dynamic Documents with Salesforce Data Integration
Description:
This detailed guide teaches you how to create a Contract Template in Salesforce using the docu2.me tool. Learn how to integrate dynamic fields, manage resources like “Dataset” and “Variables”, and automate the generation of professional documents directly in Salesforce. The process includes creating dynamic tables, configuring Flows, and generating customized PDFs based on data from “Opportunity” and related objects.
Introduction to the “Contract” Template
The “Contract – Template” is designed to streamline the creation of professional and dynamic documents within Salesforce. By leveraging Docu2.me, users can generate customized contracts that automatically pull data from Salesforce records, such as opportunities, accounts, and related products. This ensures accuracy, consistency, and efficiency in document creation.
Key Features of the Template:
- Dynamic Fields: Automatically populate fields like contractor name, contractor title, project size, and payment terms.
- Integration with Salesforce Data: Directly access and display data from Salesforce objects, including opportunities, accounts, and line items.
- Customizable Layout: Use tables, headers, and formatting tools to create a professional and visually appealing document.
- Automation: Automate the generation of PDFs with predefined templates and dynamic data.
Fields Used in the Template:
Here are the key dynamic fields integrated into the “Contract” template:
Fields Used in the Template:
Here are the key dynamic fields integrated into the “Contract” template:
General Information:
- Current Date:
{!$System.Date}
- Organization Name:
{!$Organization.Name}
- Organization Address:
{!$Organization.Street}
, {!$Organization.City}
, {!$Organization.State}
, {!$Organization.Country}
, {!$Organization.PostalCode}
Account Information (Client):
- Account Name:
{!$Record.Account.Name}
- Account Address:
{!$Record.Account.BillingStreet}
, {!$Record.Account.BillingCity}
, {!$Record.Account.BillingState}
, {!$Record.Account.BillingCountry}
, {!$Record.Account.BillingPostalCode}
Opportunity Information:
- Total Amount:
{!$Record.Amount}
- Close Date:
{!$Record.CloseDate}
Custom Variables:
- Project Size:
{!$Variable.projectSize}
- Contractor Name:
{!$Variable.contractorName}
- Contractor Title:
{!$Variable.contractorTitle}
Opportunity Line Items:
- Product Name:
{!$Dataset.OppLineItem.Product2.Name.Value}
- Quantity:
{!$Dataset.OppLineItem.Quantity.Value}
- Unit Price:
{!$Dataset.OppLineItem.UnitPrice.Value}
- Total Price:
{!$Dataset.OppLineItem.TotalPrice.Value}
User Information:
- User Name:
{!$User.Name}
- User Title:
{!$User.Title}
Page Numbering:
- Current Page:
{!$Doc.PageNumber}
- Total Pages:
{!$Doc.PageCount}
Why Use This Template?
- Efficiency: Reduces manual data entry by automatically pulling information from Salesforce records.
- Accuracy: Ensures data consistency by using real-time Salesforce data.
- Professionalism: Creates polished and standardized documents for clients and internal use.
- Flexibility: Easily customizable to meet specific business needs.
At the end of this section, you’ll find an illustrative image showing the structure of the “Contract” template and how dynamic fields are integrated.tion, you’ll find an illustrative image showing the structure of the “Contract” template and how dynamic fields are integrated.

2. Creating the Template in Docu2.me
Creating the “Contract” template in Docu2.me is a simple and intuitive process. This topic will guide you step by step through the creation of the template record, initial setup, and saving the document.
Steps to Create the Template:
- Access Docu2.me:
- Log in to Salesforce and navigate to the Docu2.me homepage under the “docu2.me Home” tab.
- Create a New Template:
- In the “docu2.me Template” tab, click “New” to create a new record.
- In the pop-up, fill in the “docu2.me Template Name” field with the name “Contract Template”.
- Click “Save” to save the record.
- Verify the Created Record:
- After saving, the record will be displayed with the name “Contract Template”.
- Note that, at this point, there are no documents associated with the template yet.
- Create a New Document:
- To create a document related to the template, go to the related records and choose the “New” option in “docu2.me Files” (located in the “docu2.me Related List” component) or click “Edit with Docu2.me” in the “Highlights Panel”.
- A new document will be created in the Docu2.me editor.
- Saving the Document:
- In this step, we’ll name the document as “Contract Template”.
- Locate the top-left section, where it says “Untitled document”, and enter the name “Contract Template”.
- After naming the document, go to the “File Menu” and select the “Save” option or use the shortcut “Ctrl+S” (Windows) or “⌘+S” (Mac) to save.
- Now, you have a blank Contract Template document ready for editing.
Important Notes:
- The template record serves as a central point to manage all related documents.
- Ensure the template and document are named clearly and descriptively for easy future identification.
At the end of this section, you’ll find an illustrative image showing the process of creating the template in Docu2.me.

3. Locating the “Contract Template” Document
After creating the template, it’s important to know how to locate it in Docu2.me for future editing or use. This topic explains how to find the “Contract Template” document in the Docu2.me interface.
Steps to Locate the Document:
- On the Docu2.me Homepage:
- After creating the template, you can find it in the “Recents Documents” section of the Docu2.me homepage (“docu2.me Home”).
- Hover over the “Contract Template” document to see the available options:
- Rename: Rename the document.
- Remove: Delete the document.
- Open in new tab: Open the document in a new browser tab.
- In the “docu2.me Templates” Tab:
- Navigate to the “docu2.me Templates” tab.
- Locate the “Contract Template” record.
- In the “docu2.me Related List” component, you’ll see the associated document under “docu2.me Files”.
- Opening the Document:
- Click on the document to open it in the same tab or use the “Open in new tab” option to open it in a new tab.
Important Notes:
- Organize your templates and documents clearly for easy future access.
- Use the rename and delete options to keep your document list updated.
At the end of this section, you’ll find an illustrative image showing how to locate the “Contract Template” document.

4. Inserting Data in the Contract Template
Now, we’ll insert data into the Contract Template, as it will be created from the Opportunities object.
Steps to Insert Data:
- Adding a Logo Image:
- With the “Contract Template” document open, go to the Insert Menu and choose the “Image” option.
- A pop-up of “Image Gallery” will open, where you can choose from images already added in Salesforce or upload a new one.
- After selecting the image, adjust its size so it’s neither too large nor too small, as it will be placed at the top of the document.
- Creating a Table with a Yellow Background:
- Next, create a table with the width of the page.
- In the toolbar button, insert a table with one row and one column.
- Choose a yellow background color for the table.
- Go to “Cell Properties”, set the border to “White”, and select the yellow color in the “Background” field.
- Then adjust the width and height of the table as desired.
- Save the table settings and write the text “Contract Agreement”.
- Format the text in bold and center it.
- Inserting a “Page Break”:
- After the table, insert a “Page Break” to start a new page.
- In a new paragraph, go to the Insert Menu and choose the “Page Break” option.
- Save Document
- Go to the “File Menu” and select the “Save” option or use the shortcut “Ctrl+S” (Windows) or “⌘+S” (Mac) to save
Important Notes:
- Ensure the logo image is well-positioned and appropriately sized.
- The table with a yellow background and the text “Contract Agreement” should be centered and visually appealing.
- The “Page Break” is essential for organizing the document into clear and well-defined sections.
At the end of this section, you’ll find an illustration showing the process of inserting data into the template.

5. Creating a “Screen Flow”
With the document now formatted, the next step is to create a Screen Flow in Salesforce to automate the document generation process. This topic will guide you through the initial setup and creation of the flow.
Steps to Create the Screen Flow:
- Access Salesforce Setup:
- In Salesforce, click the gear icon in the top-right corner and select “Setup”.
- In the left-hand menu, navigate to “Flows” and click “New Flow”.
- Choose the Flow Type:
- In the pop-up window, select the option “Start From Scratch”.
- Choose the flow type “Screen Flow” and click “Create”.
Important Notes:
- This is the first step in building the flow. In the next topics, we’ll add screens, decisions, and actions to complete the automation.
- Save your progress regularly to avoid losing any changes.
At the end of this section, you’ll find an illustrative image showing how to create a new Screen Flow.

6. Adding the “Screen” Element – “Collect Contract Data”
Now, we’ll insert the first element of the Flow. In the New Flow screen, we’ll add a new element called “Screen” and configure it with the following information:
Steps to Configure the Screen:
- Screen Settings:
- In “Screen Properties”, in the “Label” field, write “Collect Contract Data”.
- In the “API Name” field, enter “CollectContractData”.
- In “Description”, write: “This screen allows the user to input the necessary data to generate the contract, such as contractor name, title, and project timeline.”
- Header and Footer Configuration:
- In “Configure Header”, uncheck the “Show Header” option.
- In “Configure Footer”, in the “Navigation” section, under “Next or Finish Button”, choose “Use a custom label” and write “Preview” in the “Next or Finish Button Label” field.
- In the “Previous Button” section, leave the option “Hide Previous”.
- In “Pause Button”, check the “Hide Pause” option.
- Adding Components to the Screen:
- Add a component called “Display Text” (search for “Display Text” in the “Search Component”).
- Set the “API Name” to “DisplayGenerateContract”.
- In the Rich Text block, insert the phrase “Generate Contract” and format the text in bold and centered.
- Adding a Section:
- Below the “Display Text” component, add a new component called “Section”.
- In “Configure Columns”, add another column with the values of 6 of 12 (Half Width).
- Configuring Input Fields:
- Inside the first column, add an “Input” component of type “Text”.
- In the “Label” field, write “Contractor Name” and in the “API Name” field, enter “contractorName”. Mark it as “Required”.
- Add another “Input” component of type “Text”.
- In the “Label” field, write “Contractor Title” and in the “API Name” field, enter “contractorTitle”. Mark it as “Required”.
- Adding the Project Timeline Field:
- Below the two columns, add another “Input” component of type “Text”.
- In the “Label” field, write “Project will be finished in” and mark it as “Required”.
- Fill the field with the default value “30 business days”.
- Finalizing:
- After configuring all components, click “Done”.
Important Notes:
- Ensure all required fields are marked as “Required”.
- The text “Generate Contract” should be centered and bold to highlight the screen title.
At the end of this section, you’ll find an illustrative image showing the Screen configuration.

7. Saving the Flow
Now that we’ve configured the “Generate Contract” screen, the next step is to save the Flow to ensure all changes are stored correctly. This topic will explain how to save the Flow without activating it, allowing you to continue developing and testing.
Steps to Save the Flow:
- Click “Save”:
- In the bottom-left corner of the Flow editor, locate the “Save” button and click it.
- Fill in the Flow Details:
- In the pop-up that appears, fill in the following fields:
- Flow Label: Generate Contract
- Flow API Name: GenerateContract
- Description: This flow generates a contract as a PDF file based on a predefined document template and user-input data, such as contractor name, title, and project timeline. It includes steps for data collection, document preview, and PDF export.
- In the pop-up that appears, fill in the following fields:
- Save the Flow:
- After filling in the fields, click “Save” to store the Flow.
Important Notes:
- Save the Flow regularly during development to avoid losing changes.
- The Flow is not yet active, allowing you to continue editing and testing.
At the end of this section, you’ll find an illustrative image showing how to save the Flow.

8. Adding Variables and Formula
Now, we’ll add the necessary variables to continue with the Flow. In the bottom-left corner, there’s an icon for “Toggle Toolbox”. Clicking it will open a side pop-up where you can manage the Flow’s resources and elements. We’ll create the following variables:
Steps to Add Variables:
- Create the Variable “lstVariables”:
- Click the “New Resource” button.
- In the “New Resource” pop-up, choose “Resource Type” as “Variable”.
- Set the “API Name” to “lstVariables”.
- Choose “Data Type” as “Apex-defined”.
- Select “Allow multiple values (collection)”.
- Choose “Apex Class” as “docu2me__DocumentVariable”.
- Click “Done”.
- Create the Variable “varContractorName”:
- Again, click “New Resource”.
- Set the “API Name” to “varContractorName”.
- Choose “Data Type” as “Apex-defined”.
- Choose “Apex Class” as “docu2me__DocumentVariable”.
- Click “Done”.
- Create the Variable “varProjectSize”:
- Again, click “New Resource”.
- Set the “API Name” to “varProjectSize”.
- Choose “Data Type” as “Apex-defined”.
- Choose “Apex Class” as “docu2me__DocumentVariable”.
- Click “Done”.
- Create the Variable “varContractorTitle”:
- Again, click “New Resource”.
- Set the “API Name” to “varContractorTitle”.
- Choose “Data Type” as “Apex-defined”.
- Choose “Apex Class” as “docu2me__DocumentVariable”.
- Click “Done”.
- Create the Variable “recordId”:
- Again, click “New Resource”.
- Set the “API Name” to “recordId”.
- Choose “Data Type” as “Text”.
- In “Availability Outside the Flow”, check “Available for input”.
- Click “Done”.
Adding a Formula:
- Create the Formula “previewVariables”:
- Click “New Resource” and choose “Formula”.
- Set the “API Name” to “previewVariables”.
- Choose the formula’s data type as “Text”.
- Add the following formula:
"contractorName="&{!contractorName}&"&contractorTitle="&{!contractorTitle}&"&projectSize="&{!projectSize}
- Click “Done”.
Important Notes:
- Ensure all variables and the formula are correctly configured.
- Variables are essential for storing and manipulating data during Flow execution.
- The “previewVariables” formula will be used to concatenate variable values and display them in the document.
At the end of this section, you’ll find an illustration showing how to add variables and formulas to the Flow.

9. Adding the “Assignment” Component – “Set Contract Variables”
From here, we’ll add another element after the Screen “Collect Contract Data”. Now, we’ll add the logic element “Assignment”.
Steps to Configure the “Assignment” Component:
- Assignment Settings:
- In the “Label” field, write “Set Contract Variables”.
- In the “API Name” field, enter “SetContractVariables”.
- In “Description”, write: “This component stores the user-input data into variables for later use in contract generation.”
- Configuring Variable Values:
- In “Set Variable Values”, under “Each variable is modified by the operator and value combination”, insert the following values:
Variable | Operator | Value |
{!varProjectSize.name} | Equals | projectSize |
{!varProjectSize.value} | Equals | {!projectSize} |
{!lstVariables} | Add | {!projectSize} |
{!varContractorName.name} | Equals | contractorName |
{!varContractorName.value} | Equals | {!contractorName} |
{!lstVariables} | Add | {!varContractorName} |
{!varContractorTitle.name} | Equals | contractorTitle |
{!varContractorTitle.value} | Equals | {!contractorTitle} |
{!lstVariables} | Add | {!varContractorTitle} |
Important Notes:
- The “Assignment” component is essential for storing user-input data in variables that will be used later in contract generation.
- Ensure all variables are correctly configured to avoid errors during Flow execution.
At the end of this section, you’ll find an illustrative image showing how to configure the “Assignment” component.

10. Getting the Document Template
In this topic, we’ll use the “Get Records” component in the Flow to retrieve the template we created. This way, we’ll search for the “Contract Template” record from the “docu2.me Template” object.
Steps to Configure the “Get Records” Component:
- “Get Records” Settings:
- In the “Label” field, write “Get Contract Template Document”.
- In the “API Name” field, enter “GetContractTemplateDocument”.
- In “Description”, write: “This component retrieves the specific Docu2me template document for the contract based on the template name. It ensures the correct template is used for generating the contract PDF.”
- Configuring the Object and Filters:
- In “Get Records of This Object”, search for the “docu2.me Template” object.
- In “Filter docu2.me Template Records”, configure the following conditions:
- Condition Requirements: All Conditions Are Met (AND)
- Field: Name
- Operator: Equals
- Value: Contract Template
Important Notes:
- The “Get Records” component is essential for retrieving the correct template that will be used in contract generation.
- Ensure the template name (“Contract Template”) matches exactly as created to avoid search errors.
At the end of this section, you’ll find an illustrative image showing how to configure the “Get Records” component.

11. File Preview Screen
In this topic, we’ll add a new “Screen” element that will become a “File Preview”, where the user can preview the PDF before generating the final file.
Steps to Configure the “Preview Contract Document” Screen:
- Screen Settings:
- In the “Label” field, write “Preview Contract Document”.
- In the “API Name” field, enter “PreviewContractDocument”.
- In “Description”, write: “This screen allows the user to preview the contract before generating the final PDF.”
- Header and Footer Configuration:
- In “Configure Header”, uncheck the “Show Header” option.
- In “Configure Footer”, under “Next or Finish Button”, check “Use a custom label” and enter “Generate PDF” in the “Next or Finish Button Label” field.
- In “Pause Button”, check the “Hide Pause” option.
- Adding the “docu2.me File Preview” Component:
- In “Components”, search for “docu2.me File Preview” and click to add it to the center of the screen.
- Configure the following data:
- API Name: FilePreview
- Document Id: {!GetContractTemplateDocument.Id}
- Record Id: {!recordId}
- Variables: {!previewVariables}
- Click “Done”.
Important Notes:
- The “Preview Contract Document” screen allows the user to preview the contract before generating the final PDF, ensuring everything is correct.
- Ensure the “Document Id”, “Record Id”, and “Variables” fields are correctly configured to display the document properly.
At the end of this section, you’ll find an illustrative image showing how to configure the preview screen.

12. Action to Export Contract as PDF
The next step is to create an action to export the document as a PDF. First, we’ll add a new interaction element, which will be an “Action” element, and configure it to export the contract.
Steps to Configure the “Export Contract as PDF” Action:
- Action Settings:
- In the “Label” field, write “Export Contract as PDF”.
- In the “API Name” field, enter “ExportContractPDF”.
- In “Description”, write: “This component exports the contract as a PDF file based on the document template and user-input data.”
- Configuring Input Values:
- In “Set Input Values for the Selected Action”, fill in the following information:
- Export As: PDF
- Filename: Business_Contract
- This can be ContentDocumentId, ContentVersionId or docu2.me Template Id: {!GetContractTemplateDocument.Id}
- Record Id utilized as the parent of the generated document: Enable the “Include” button and enter {!recordId}.
- Variables Values: Enable the “Include” button and enter {!lstVariables}.
- In “Set Input Values for the Selected Action”, fill in the following information:
Important Notes:
- The “Export Contract as PDF” action is essential for generating the final contract in PDF format, using the template and user-input data.
- Ensure the input values are correctly configured to avoid errors during export.
At the end of this section, you’ll find an illustrative image showing how to configure the preview screen.

13. Inserting Data into the “Template Contract” part 1
With the “Screen Flow” for “Generate Contract” completed, let’s return to editing the “Contract Template”.
Steps to Insert Data into the Template:
- Accessing the Template:
- Go to the docu2.me app and navigate to the “docu2.me Templates” tab.
- Select the “Contract Template” record.
- Editing the Document:
- With the docu2.me text editor open, start inserting the remaining data.
- Adding the Title:
- Write the text: “Contractor Agreement”.
- Format the text as “Heading 1” using the formatting toolbar or go to Menu Format > Paragraph Styles > Heading 1 (or use the shortcut Ctrl+Alt+1 or ⌘+Option+1).
- Center the text using Menu Format > Align & Indent > Center (or use the shortcut Ctrl+Shift+E or ⌘+Shift+E).
- Inserting the Initial Text:
- In the next paragraph, write:
"This Contractor Agreement ("Agreement") is made and entered into as of this"
- After the text, right-click and select “Select Object”.
- Choose the “Opportunity” object and, in “Select a resource from global variable”, go to “System” and select the “Current Date” option. This will add the
{!$System.Date}
field. - Make the field bold.
- Completing the Text:
- Add the remaining text and dynamic fields to complete the paragraph:
“This Contractor Agreement (“Agreement”) is made and entered into as of this {!$System.Date}, by and between {!$Organization.Name}, with its principal place of business at {!$Organization.Street}, {!$Organization.City} – {!$Organization.State}/{!$Organization.Country}, {!$Organization.PostalCode} (“Company”) and {!$Record.Account.Name}, with its principal place of business at {!$Record.Account.BillingStreet}, {!$Record.Account.BillingCity}/{!$Record.Account.BillingState}/{!$Record.Account.BillingCountry}, {!$Record.Account.BillingPostalCode} – (“Contractor”).”
Important Notes:
- Ensure all dynamic fields are correctly inserted and formatted.
- The text should be organized and clear to facilitate reading and understanding the contract.
At the end of this section, you’ll find an illustrative image showing how to insert data into the template.

14. Inserting Data into the “Template Contract” part 2
With the first part of the contract text inserted, let’s now add the remaining data.
Steps to Insert the Remaining Data:
- Adding the “Services” Section:
- Insert the following text:
“Services
The Contractor agrees to perform the following services (“Services”): Development and implementation of a customized CRM system for {!$Organization.Name}. The Contractor shall provide these Services at a time and place as agreed upon by both parties.”
- Adding the “Compensation” Section:
- Insert the following text:
“Compensation
In consideration for the Services rendered, the Company agrees to pay the Contractor the sum of {!$Record.Amount} upon completion of the Services or on the following payment schedule: 50% upon project initiation and 50% upon project completion. The Contractor shall submit detailed invoices to the Company, and the Company agrees to pay the approved invoices within 15 days of receipt.”
- Adding the “Term and Termination” Section:
- Insert the following text:
“Term and Termination
This Agreement shall commence on {!$Record.CloseDate} and has the expectation to be finished in”
- After the text, right-click and choose the “Resource Manager” option.
- In the pop-up, select “New Resource” and choose “Variable”.
- Select the “projectSize” variable created in the “Screen Flow” of the “Assignment” “Set Contract Variables”.
- Copy the value of “projectSize” and paste it into the “Variable API Name” field.
- Save and add the variable.
- Again, right-click after the text, add “Dynamic Fields”, and edit
{!$Variable.projectSize}
in bold. - Complete the remaining text:
“This Agreement shall commence on {!$Record.CloseDate} and has the expectation to be finished in {!$Variable.projectSize}.”
- Add a “Page Break” at the end of the text.
Important Notes:
- Ensure all dynamic fields are correctly inserted and formatted.
- The text should be organized and clear to facilitate reading and understanding the contract.
At the end of this section, you’ll find an illustrative image showing how to insert the remaining data into the template.

15. Inserting Data into the “Template Contract” part 3
After inserting the “Page Break”, let’s add the remaining text and a table with information about the contracted products.
Steps to Insert the Remaining Data:
- Adding the Final Sections:
- Insert the following text:
“4. Confidentiality
The Contractor agrees to maintain the confidentiality of any proprietary or confidential information disclosed during the term of this Agreement. This clause shall survive the termination of the Agreement.
5. Independent Contractor
The Contractor acknowledges that they are an independent contractor and not an employee, agent, or partner of the Company. The Contractor shall be solely responsible for all taxes, withholdings, insurance, and any other obligations.
6. Governing Law
This Agreement shall be governed by and construed in accordance with the laws of the State of California. Any legal actions, claims, or demands shall be handled in a court of competent jurisdiction within California.
7. Product Contracted”
- Creating the Products Table:
- Add a table using the “Table” toolbar with 4 columns and 3 rows.
- Format the column header with a gray color and insert the following titles:
- Product
- Qty.
- Unity Price
- Total Price
- Merge the last row of 3 columns and write “TOTAL”.
- Configuring the Dataset:
- Below “Product”, right-click and select “Resource Manager”.
- In the pop-up, choose “New Resource” and select “Dataset”.
- Configure the Dataset with the following information:
- Dataset API Name: OppLineItem
- Object Name: Opportunity Product
- How to Filter Records – Condition Requirements: All conditions are met (AND)
- Field: Opportunity ID
- Operator: Equal
- Value:
{!$Record.Id}
- How to Sort Records – Sort Order: Ascending
- Sort By: Opportunity Product Name
- How Many Records – Maximum Number of Records: 19
- Click “Save”.
- Inserting Dynamic Fields into the Table:
- In the first row below “Product”, right-click and select “Dynamic Field”.
- Go to “Dataset” > “OppLineItem” and choose “Opportunity Product Name” in the “Value” option. This will add
{!$Dataset.OppLineItem.Name.Value}
. - Complete the other fields in the table:
Product:{!$Dataset.OppLineItem.Product2.Name.Value}
Qty.:{!$Dataset.OppLineItem.Quantity.Value}
Unity Price:{!$Dataset.OppLineItem.UnitPrice.Value}
Total Price:{!$Dataset.OppLineItem.TotalPrice.Value}
TOTAL: {!$Record.Amount}`
- Finalizing:
- After completing the table, add a “Page Break”.
Important Notes:
- Ensure all dynamic fields are correctly inserted and formatted.
- The table should be organized and clear to facilitate reading and understanding the contracted products.
At the end of this section, you’ll find an illustrative image showing how to insert the remaining data into the template.

16. Inserting Data into the “Template Contract” Final
In this final editing step, we’ll insert a “Filter Block” to filter and display a section of the contract text only for the state of “Florida” in the United States.
Steps to Insert the “Filter Block” and Complete the Template:
- Adding the “Filter Block”:
- After the “Page Break”, in the next paragraph, right-click and select the “Filter Block” option.
- In the text box that appears, go to “Configuration” and select the field “Account” > “Billing State/Province”.
- In “Select a condition”, choose “Equal” and enter the value “‘FL'”.
- Click the “+” sign to add and confirm with the button.
- Inserting Text into the “Filter Block”:
- Inside the “Filter Block” text box, add the following text:
“8. Florida State Law
The government of Florida requires a contentment of pay additional tax of 6% before the service being started.”
- Adding the Signatures Paragraph:
- After the “Filter Block”, add the following text:
“Signatures
IN WITNESS WHEREOF, the parties hereto have executed this Contractor Agreement as of the day and year first above written.”
- Adding Variables and Signature Fields:
- Use the “Resource Manager” to add the variables “contractorTitle” and “contractorName”.
- Add the following fields with the default values:
“Company
Name: {!$User.Name}
Title: {!$User.Title}, {!$Organization.Name}
Date: {!$System.Date}
Contractor
Name: {!$Variable.contractorName}
Title: {!$Variable.contractorTitle}
Date: {!$System.Date}”
Important Notes:
- The “Filter Block” ensures that the section about Florida law is displayed only when the state is “FL”.
- Ensure all variables and dynamic fields are correctly inserted and formatted.
At the end of this section, you’ll find an illustrative image showing how to complete the template editing.

17. Creating an Action Button on the “Opportunity” Object
In this topic, we’ll create an action button on the “Opportunity” object to allow users to generate the “Contract Template” document directly from an “Opportunity” record. This action button will call the “Generate Contract” Flow to generate the document in PDF format.
Steps to Create the Action Button:
- Access the “Opportunity” Object Setup:
- In any “Opportunity” record, click the gear icon in the top-right corner and select “Setup”.
- In the left-hand menu, go to “Object Manager” and search for “Opportunity”.
- In “Opportunity”, click on “Buttons, Links, and Actions”.
- Create a New Action Button:
- Click on “New Action”.
- Configure the following information:
- Object Name: Opportunity
- Action Type: Flow
- Flow: Generate Contract
- Label: Generate Contract
- Name: GenerateContract
- Description: This button will create a block in Flow where it will generate an contract.
- Click “Save” to save the action button.
- Add the Action Button to the Record Page:
- Return to an “Opportunity” record and click the gear icon in the top-right corner.
- Select “Edit Page”.
- This will open the “Lightning App Builder” related to the “Opportunity” record page.
- Add the Button to the “Highlight Panel”:
- In the “Lightning App Builder”, select the “Highlight Panel” component at the top of the page.
- In the properties panel on the right, click “Add Action”.
- In “Object-Specific Quick Actions”, select the “Generate Contract” action button you created.
- Position the button so it’s visible to the user.
- Save and Activate the Page:
- Click “Save” to save the changes.
- Click “Activate” to activate the updated page.
Important Notes:
- Ensure the “Generate Contract” Flow is correctly configured before creating the action button.
- Test the action button to ensure the document is generated as expected.
At the end of this section, you’ll find an illustrative image showing how to create and add the action button to the “Opportunity” record page.

18 – Generate Contract
In this topic, we’ll use the “Generate Contract” action button to generate a contract from the “Contract Template”. The document can be previewed, saved in Salesforce, printed, or downloaded as a PDF.
Steps to Generate the Contract:
- Check the “Opportunity” Record Fields:
- In an “Opportunity” record, ensure all necessary fields are filled out for the creation of the contract document.
- Click the “Generate Contract” Button:
- With the fields filled out, click the “Generate Contract” action button located in the “Highlight Panel” of the “Opportunity” record page.
- Fill in the Fields in the Pop-up:
- After clicking “Generate Contract”, a pop-up will open with the following fields:
- Contractor Name: Alex Avila
- Contract Title: Administrator
- Project will be finished in: 30 business days
- Click “Preview” to preview the contract in PDF.
- Generate the PDF:
- After previewing the contract, click “Generate PDF” to create the final document.
- The contract will be attached to the “Opportunity” record in the “Files” component with the name “Business_Contract”.
- Click the file to view the completed contract.
Important Notes:
- Ensure all necessary fields are correctly filled out before generating the contract.
- The generated contract can be saved, printed, or downloaded as needed.
At the end of this section, you’ll find an illustrative image showing how to generate the contract.

Final Considerations
The process of creating and implementing the “Template Contract” was designed to simplify and automate contract generation in Salesforce, ensuring efficiency, accuracy, and consistency. Here are some key points to reflect on:
1. Efficiency and Automation:
- The use of Flows, Dynamic Fields, and Datasets allowed for the automation of a process that could otherwise be manual and prone to errors.
- The integration of the “Generate Contract” action button directly into the “Opportunity” object makes it easy for users to access and quickly generate contracts.
2. Customization and Flexibility:
- The “Template Contract” was designed to be highly customizable, allowing for the inclusion of dynamic fields that adapt to the specific information of each record.
- The use of “Filter Blocks” and “Conditional Logic” ensures that only relevant information is displayed, such as the section on Florida law.
3. Preview and Validation:
- The “Preview” functionality allows users to review the contract before generating the final PDF, ensuring all information is correct.
- This reduces the need for later revisions and increases confidence in the generated document.
4. Storage and Access:
- The generated contract is automatically attached to the “Opportunity” record in the “Files” component, making it easy to access and manage the document.
- This also ensures that the contract is always associated with the correct record, avoiding loss or confusion.
5. Scalability:
- The process can be easily scaled to other objects or document types, such as proposals, invoices, or service agreements.
- The modular structure of the Flow and template allows for quick adaptations to different business needs.
6. Future Improvements:
- To further enhance the process, consider adding automatic email notifications when the contract is generated.
- Another improvement would be integrating with e-signature tools like DocuSign to streamline the signing and approval of contracts.
7. Testing and Validation:
- Before implementing the process in production, it’s essential to conduct thorough testing to ensure all dynamic fields, formulas, and conditions work as expected.
- Involve end-users in the testing process to gather feedback and identify potential improvements.
Conclusion
The “Template Contract” is a powerful solution that combines automation, customization, and efficiency to simplify contract generation in Salesforce. By following the steps outlined, you can create a robust process that meets your organization’s needs, saving time and reducing errors.