Sample Flow to Renew Contracts Using Input Parameters Derived from Fields on Account Extension

This page describes a sample flow to renew contracts automatically using input values derived from fields on account extension records. By creating custom fields on the Account Extension object, you can specify renewal options by account. For example, some accounts might want renewal prices to be derived from a price book, whereas other accounts might want renewal prices to be calculated from a percentage.

Warning:

This page does not give step-by-step instructions on how to create the sample flow. The information is intended for administrators who are already experienced at creating Salesforce flows. Refer to the Salesforce Help if you need information about how to create flows.

Prerequisites

This sample flow has the following prerequisites:

  1. On the Account Extension object, create the following custom fields. When creating the picklist values, their labels can be descriptive but their API names must match those given below.

    Label API Name Data Type API Name of Picklist Values
    Renewal Contract Duration RenewalContractDuration__c Picklist

    AsMonths

     

    AsDays

    Renewal Start And End Dates RenewalStartAndEndDates__c Picklist

    KeepSame

     

    ExtendToMatchContractDuration

    Renewal Price Book RenewalPriceBook__c Lookup to Price Book -
    Renewal Price Change RenewalPriceChange__c Percent -
  2. In Billing Central, select the Automatically Populate Renewal Contract field in the Billing Central Settings custom setting. This configures Billing Central to link a contract to its renewal automatically. Billing Central does this by populating the Renewal Contract field on the original contract with a lookup to the renewal.
  3. In the Flow Builder, go to the Toolbox and create a variable of Data Type = Text to store error messages. Name this variable RenewalErrorMessage.

    Screenshot of New Resource window in the Flow UI

  4. In the Flow Builder, go to the Toolbox and create a variable of Data Type = Boolean to store the success/fail outcome of the renewal action. Name this variable RenewalHasErrors.

    Screenshot of New Resource window in the Flow UI

The Sample Flow

This sample flow is a Schedule-Triggered Flow where input parameters for the Renew Billing Contracts Asynchronously Apex action are derived from fields on account extension records. Unit prices on the renewal are derived from a price book if supplied on the account extension, otherwise from the supplied percentage. The Apex action interprets a blank percentage as 0% so if no percentage is supplied, the renewal is created with the billing contract's existing unit prices. If an error occurs in either outcome, the returned error message is emailed to the user.

Diagram of Sample Flow to Renew Contracts with or without A Price Book

An explanation of each numbered item is provided in the table below.

# Flow Element Sample Flow Suggestion Sample Flow Setup
1 Flow Element: Start On the Start element, click Set Schedule and enter appropriate schedule details. Note that the Start Time is in the org's default time zone. Screenshot of Set a Schedule window in the Flow UI
1 Flow Element: Start On the Start element, click Choose Object. Set the object to Billing Contract and enter the following conditions so that the flow only attempts to renew contracts that are Active, have an End Date, and do not have a Renewal Contract (i.e. have not already been renewed):

ffbc__Status__c Equals Active
ffbc__EndDate__c Is Null False
ffbc__RenewalContract__c Is Null True

Warning:

These conditions mean that the flow will attempt to renew ALL active contracts in the org that haven’t already been renewed once. You can narrow down which contracts are renewed further by adding additional conditions. For example, you could add a condition to only renew contracts where the Renewal Date is in the past. This condition would be:

ffbc__RenewalReminder__c Less Than <date>

where <date> could be today's date or another fixed date in the recent past.

Screenshot of Choose Object and Filter Conditions window in the Flow UI
2 Flow Element: Get Records

Add a Get Records element. Set the object to Account Extension and enter the following condition so that the flow retrieves the account extension record for the account on the billing contract:

fferpcore__Account__c Equals {!$Record.ffbc__Account__c}

Screenshot of New Get Records window in the Flow UI
3 Flow Element: Decision Add a Decision element to check if a price book is supplied. Rename the default outcome to Pricebook Does Not Exist then

create a Pricebook Exists outcome with the condition:

{!Get_Account_Extension.RenewalPriceBook__c} Is Null False

Screenshot of New Decision window in the Flow UI
4 Flow Element: Apex Action For the Pricebook Exists outcome, add an Action element to renew contracts with a price book. Choose the Renew Billing Contracts Asynchronously action, then complete the input and output values.

Set Input Values - some of these use custom fields you created on the Account Extension object in "Prerequisites" step 1. Do not include a Percentage input value.

Note:

If you specify the fields on the Account Entension object using __r rather than __c you will need to append .Id to the end of the path.

Billing Contract ID to be renewed:{!$Record.Id}
Contract duration option: {!Get_Account_Extension.RenewalContractDuration__c}
Contract line duration option: {!Get_Account_Extension.RenewalStartAndEndDates__c}
Percentage: Don't Include

Pricebook ID: {!Get_Account_Extension.RenewalPriceBook__c}

Store Output Values - assign these to the variables you created in "Prerequisites" steps 3 and 4.

Error Message: {!RenewalErrorMessage}
Has Errors: {!RenewalHasErrors}

Screenshot of New Action window in the Flow UI
5 Flow Element: Assignment Add a fault path to the Apex action created at #4, then add an Assignment element to the fault path. Set the following variable value so that if a fault is returned by the flow it is stored in the RenewalErrorMessage variable:

{!RenewalErrorMessage} Equals {!$Flow.FaultMessage}

Screenshot of New Assignment window in the Flow UI
6 Flow Element: Apex Action For the Pricebook Does Not Exist outcome, add an Action element to renew contracts without a price book. Choose the Renew Billing Contracts Asynchronously action, then complete the input and output values.

Set Input Values - some of these use custom fields you created on the Account Extension object in "Prerequisites" step 1. Do not include a Pricebook ID input value.

Note:

If you specify the fields on the Account Entension object using __r rather than __c you will need to append .Id to the end of the path.

Billing Contract ID to be renewed:{!$Record.Id}
Contract duration option: {!Get_Account_Extension.RenewalContractDuration__c}
Contract line duration option: {!Get_Account_Extension.RenewalStartAndEndDates__c}
Percentage: {!Get_Account_Extension.RenewalPriceChange__c}

Pricebook ID: Don't Include

Store Output Values - assign these to the variables you created in "Prerequisites" steps 3 and 4.

Error Message: {!RenewalErrorMessage}
Has Errors: {!RenewalHasErrors}

Screenshot of New Action window in the Flow UI
7 Flow Element: Fault Path Add a fault path to the Apex action created at #6, then connect this fault path to the Assignment element at #5. This ensures that if an error occurs in either the Pricebook Exists or Pricebook Does Not Exist outcome, the error is handled in the same way.  
8 Flow Element: Decision

Before the final End element, add a Decision element to check for errors. Create a Renewal Has Errors outcome for if the Apex action returns an error. The condition for this outcome is:

RenewalHasErrors Equals True

Screenshot of New Decision window in the Flow UI
9 Flow Element: Action For the Renewal Has Errors outcome, add a Send Email action then complete the input values.

Set Input Values

Body: An error occurred when renewing {!$Record.Name} :{!RenewalErrorMessage}
Subject: Renewal Failed for Record {!$Record.Id}
Recipient Email Addresses (comma-separated): {!$Record.Owner:User.Email}
Sender Email Address: {!$User.Email}

Screenshot of New Action window in the Flow UI
10 Flow Element: Assignment Connect the fault path from the Assignment element created at #5 to the Send Email action created at #9. This means that regardless of whether an error occurs in the Pricebook Exists or Pricebook Does Not Exist outcome, it is emailed to the user in the same way.  
11 Flow Element: End Both outcomes from the Check for Errors decision are now ended. The Flow Builder might display the two outcomes finishing at the same End element, or at separate End elements. This makes no difference to flow behavior.  
  Activate the flow Remember to save and activate the flow to make it available for use.