Skip to main content

Add Conditions to Template Sections

Learning Objectives

After completing this unit, you’ll be able to:

  • Show and hide template sections based on conditions.
  • Attach a repeating header to a quote template.
  • Set up two template sections where only one is shown at a time.

Know When to Show ’Em

It’s common for businesses to have more than one kind of proposal to handle different quoting scenarios. For example, they might have a formal proposal that includes a cover page, and another more casual proposal that skips the cover. What if you could support both proposals in a single quote template? You can, by making any template section appear conditionally using its Conditional Print Field.

The Conditional Print Field on a template section tells CPQ which quote field should determine when the section appears. For example, you could have a checkbox on the quote named Include Cover Page, which sales reps can check as needed. Then, when the proposal is generated CPQ looks at the checkbox, and if it’s checked the section gets put into the proposal.

Let’s see how to set up this example by first creating the checkbox on the quote object.

  1. Click Setup icon and click Setup. The Setup page opens in a new tab.
  2. Click Object Manager.
  3. Click Quote.
  4. Click Fields & Relationships.
  5. Click New.
  6. Choose Checkbox.
  7. Click Next.
  8. For Field Label, enter Include Cover Page.
    Double-check that the Field Name is set to “Include_Cover_Page” when you click out of the label box. We rely on that exact name in later steps, so it must be correct!
  9. Click Next.
  10. Click Next to keep field level security as is.
  11. Click Save.

Now you have a field that your sales reps can toggle whenever they want a cover page. Next, you have to update the Conditional Print Field picklist so that the new field can be selected on any given template section.

  1. Click Object Manager.
  2. Click Template Section.
  3. Click Fields & Relationships.
  4. Click Conditional Print Field.
  5. In the Values section, click New.
  6. Enter Include_Cover_Page__c.
    This is the API name of your checkbox field. Whenever you refer to fields in a CPQ picklist, use the API name.
  7. Click Save.

Great, you can close the Setup tab. Now you create the template content record for your cover page.

  1. In the navigation bar, click Template Content.
  2. Click New.
  3. Choose HTML.
  4. Click Continue.
  5. For Content Name, enter AW Cover Page.
  6. Click Source.
  7. Paste the following code into the Markup window.
    <table border="1" cellpadding="1" cellspacing="1">
      <tbody>
        <tr>
          <td style="width: 40%; padding: 10px; border-right: solid black;">
            <p style="text-align: right; font-size:20px;">Proposal for</p>
            <p style="text-align: right; font-size:24px;">{!quote.SBQQ__BillingName__c}</p>
            <p style="text-align: right; font-size:20px;"> </p>
            <p style="text-align: right; font-size:20px;">Prepared by</p>
            <p style="text-align: right; font-size:24px;">{!template.SBQQ__CompanyName__c}</p>
            <p style="text-align: right; font-size:20px;"> </p>
            <p style="text-align: right; color:#D3D3D3;">Version {!document.SBQQ__Version__c}</p>
          </td>
          <td style="width: 60%; padding: 30px;">
            <p><img height="120" src="https://developer.salesforce.com/files/awcomputinglogo.png" /></p>
          </td>
        </tr>
      </tbody>
    </table>
  8. Click Save.

Your new content will look like this when added to a proposal.

Portion of proposal with company names and a logo.

The last step is to make a template section for the cover page content, and at the same time tell CPQ to use the checkbox field for the Conditional Print Field.

  1. In the navigation bar, click Quote Templates.
  2. Click AW Proposal.
  3. Click the Related tab.
  4. In the Sections related list, click New.
  5. For Section Name, enter Cover Page.
  6. For Content, find and select AW Cover Page.
  7. For Top Margin, enter 1.
  8. For Display Order, enter 1.
  9. For Conditional Print Field, choose Include_Cover_Page__c.
  10. For Page Break, choose After.
  11. Click Save.

Good work, your template section will respond to Include_Cover_Page__c. Let’s test it with our sample quote to see if the cover page appears only when it should.

  1. In the navigation bar, click Quotes.
  2. Click Q-00053.
  3. Click Preview Document.
  4. Click Preview.
    The proposal should look just like it did last time, without your new cover page, since Include Cover Page defaults to unchecked.
  5. Click X to close the preview overlay.
  6. Click Cancel.
    Let’s change the quote data to make the proposal appear.
  7. Click Edit.
  8. Check Include Cover Page.
    If you don't see the checkbox, refresh the page in your browser.
  9. Click Save.
  10. Click Preview Document.
  11. Click Preview.

Excellent, your cover page now appears as the first page, with a page break separating it from the next template section.

In this example you used a checkbox to answer the question, “Should CPQ include this section in the proposal?” There are other field types that will make a section appear too.

  • Text and picklist fields that have a literal value of “true”
  • Numeric and currency fields that have a non-zero value
  • Formula fields that return “true” or non-zero values

Add a Simple Header

Some template content needs to appear on every page, not just the one location defined in a template section record. For example, headers and footers typically appear repeatedly. For that reason, CPQ allows you to associate some template content directly to the quote template. Let’s make a simple header that has the quote number, the expiration date, and AW Computing’s company logo, then have it appear on all pages except the first.

  1. In the navigation bar, click Template Content.
  2. Click New.
  3. Choose HTML.
  4. Click Continue.
  5. For Content Name, enter AW Header.
  6. Click Source.
  7. Paste the following code into the Markup window.
    <table border="1" cellpadding="1" cellspacing="1">
      <tbody>
        <tr>
          <td>
            <p style="font-size: 16px">Quote {!quote.Name} v{!document.SBQQ__Version__c}</p>
            <p style="font-size: 12px; color:#D3D3D3;">Expires {!quote.SBQQ__ExpirationDate__c}</p>
          </td>
          <td>
            <p style="text-align: right;"><img height="40" src="https://developer.salesforce.com/files/awcomputinglogo.png" /></p>
          </td>
        </tr>
      </tbody>
    </table>
  8. Click Save.

Great, now that you have some content for a basic header, you tell CPQ to use the content in the AW Proposal template.

  1. In the navigation bar, click Quote Templates.
  2. Click AW Proposal.
  3. Click Edit.
  4. For Header Content, find and select AW Header.
  5. For Exclude Header & Footer, choose First Page.
    This will remove the header from the first page of the document, which is typically the cover page.
  6. For Header Height, enter 60.
    This creates a 60 pixel space for the header to appear. If you leave the height blank then the content ends up overlapping with the first template section on the page.
  7. Click Save.

Now when you preview the proposal for Q-00053, the second page will look like this. Nice work!

Header portion of a proposal document showing quote number and company logo.

Create a Reverse Conditional Formula

Right now the AW Proposal is set to skip the header on the first page because we don’t want it to appear on the cover page. But sometimes proposals don’t have cover pages because of the Conditional Print Field. That means it’s possible to make a proposal that starts directly with the contact details section, which doesn’t look great. It would look much better to show the header on the first page whenever the cover page is not included. To do this you make a template section for the first page header, and make it conditional on a custom formula checkbox field that always returns the opposite of Include Cover Page. You start by making the formula field in Setup.

  1. Click Setup icon and click Setup. The Setup page opens in a new tab.
  2. Click Object Manager.
  3. Click Quote.
  4. Click Fields & Relationships.
  5. Click New.
  6. Choose Formula.
  7. Click Next.
  8. For Field Label, enter Include Header.
    Again, it’s important to name this exactly right, so double-check that Field Name is Include_Header when you click out of the label box.
  9. Choose Checkbox.
  10. Click Next.
  11. For Simple Formula, enter IF(Include_Cover_Page__c, false, true).
    This simple formula returns the opposite of Include Cover Page.
  12. Click Next.
  13. Click Next to keep field level security as is.
  14. Click Save.

Next, you update the Conditional Print Field picklist, just like you did at the beginning of this unit.

  1. Click Object Manager.
  2. Click Template Section.
  3. Click Fields & Relationships.
  4. Click Conditional Print Field.
  5. In the Values section, click New.
  6. Enter Include_Header__c.
  7. Click Save.

Good, you’re done with the Setup tab and can close it. Finally, let’s add a template section for the header to appear at the beginning of the document, making it conditional based on your new formula field.

  1. In the navigation bar, click Quote Templates.
  2. Click AW Proposal.
  3. Click the Related tab.
  4. In the Sections related list, click New.
  5. For Section Name, enter First Page Header.
  6. For Content, find and select AW Header.
  7. For Display Order, enter 1.
    It’s OK to use the same display order as the cover page, since only one of the two sections will ever appear in the same proposal.
  8. For Bottom Margin, enter 0.25.
  9. For Conditional Print Field, choose Include_Header__c.
  10. Click Save.

Now whenever Include Cover Page is false, Include Header is true. In that scenario the top of the first page will look like this:

Top of first page displaying header content, followed by contact details.

A proposal can become truly dynamic by using core Salesforce functionality such as formulas and Flows to govern the value of Conditional Print Fields. You can also use CPQ price rules to set field values dynamically. Learn about price rules in the Price Rules in Salesforce CPQ badge.

Resources

Salesforce ヘルプで Trailhead のフィードバックを共有してください。

Trailhead についての感想をお聞かせください。[Salesforce ヘルプ] サイトから新しいフィードバックフォームにいつでもアクセスできるようになりました。

詳細はこちら フィードバックの共有に進む