Sample Flow to Renew Contracts Using Fixed Input Parameters

This page describes a sample flow to renew contracts automatically with a price uplift of 40%.

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. 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.
  2. 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

  3. 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 are passed to the Renew Billing Contracts Asynchronously Apex action as fixed values. There are two outcomes: a success outcome, and an error outcome which results in the returned error message being emailed to the user.

Diagram of Sample Flow to Renew A Contract Using Fixed Input Parameters

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: Apex Action Add an Action element. Choose the Renew Billing Contracts Asynchronously action, then complete the input and output values.

Set Input Values

Billing Contract ID to be renewed: {!$Record.Id}
Contract duration option: AsMonths
Contract line duration option: KeepSame
Percentage: 40

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

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

Screenshot of New Action window in the Flow UI
3 Flow Element: Decision

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
4 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
5 Flow Element: End Both the Renewal Has Errors outcome and the default outcome 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.