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.
Prerequisites
This sample flow has the following prerequisites:
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
-
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.
In the Flow Builder, go to the Toolbox and create a variable of Data Type = Text to store error messages.
Name this variable RenewalErrorMessage.
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.
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.
An explanation of each numbered item is provided in the table below.
#
Flow Element
Sample Flow Suggestion
Sample Flow Setup
1
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.
1
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
2
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:
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
4
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.
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
Store Output Values - assign these to the variables you created in "Prerequisites" steps 3 and 4.
Error Message: {!RenewalErrorMessage} Has Errors: {!RenewalHasErrors}
5
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:
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.
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}
7
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
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
9
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}
10
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
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.