Sample Flow to Apply Service Credit via a Screen Flow

This page describes a sample flow to add a service credit to an active billing contract by entering credit information via a screen.

This sample flow does not include error handling. For an illustration of how to build error handling into a flow, see either of the sample flows for renewing contracts at Sample Flows to Renew Contracts.

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 the Flow Builder, go to the Toolbox and create a variable of Data Type = Text to store the ID of the active contract that a service credit line will be added to. Name this variable recordId. Select the Available for input checkbox.

    Screenshot of New Resource window in the Flow UI

  2. In the Flow Builder, go to the Toolbox and create a variable of Data Type = Text to store the ID of the change request that is created to add the service credit line to the active contract. Name this variable ChangeRequestId.

    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 = Date to store the date that Billing Central calculates to be the contract's next billing date. Name this variable NextBillingDate.

    Screenshot of New Resource window in the Flow UI

  4. In the Flow Builder, go to the Toolbox and create a new resource of Resource Type = Record Choice Set. Name this resource Products then complete the following values:
    Object: Product

    Filter Product Records, Condition Requirements: All conditions are met (AND)
    Then add the following condition:
    ProductCode contains Credit

    Configure Each Choice
    Choice Label: Product Name
    Data Type: Text
    Choice Value: Product ID

    Screenshot of New Resource window in the Flow UI

    Note:

    This means that when users enter the service credit information on screen, any product with a Product Code containing Credit can be selected as the service credit product.

The Sample Flow

This sample flow is a Screen Flow where the user enters a contract's service credit information via a screen. Billing Central then creates a change request for the service credit line, calculates the next billing date for the service credit line, then applies the change request to the active contract.

Diagram of Sample Flow to Apply a Service Credit via Screen Input

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

# Flow Element Sample Flow Suggestion Sample Flow Setup
1 Flow Element: Start Create a new Screen Flow.  
2 Flow Element: Screen

Add a Screen element and enter a label such as Apply Service Credit.

Add the following components to the screen:

Component Label Require Parameters
Choice Lookup Credit Category Y Choice: set this to the Products Record Choice Set you created in "Prerequisites" step 4.
Number Credit Amount Y Decimal Places: 9
Date Credit Period Start Date Y -
Date Credit Period End Date Y -
Text Description Y -
Screenshot of Screen Component in Flow UI
3 Flow Element: Apex Action

Add an Action element. Choose the Create Change Requests action, then complete the input and output values.

Set Input Values

Contract ID to create change request for: {!recordId}

Store Output Values - assign this to the variable you created in "Prerequisites" step 2.

ID of newly created change request: {!ChangeRequestId}

Screenshot of New Action window in the Flow UI
4 Flow Element: Apex Action

Add an Action element. Choose the Calculate Next Billing Dates action, then complete the input and output values.

Set Input Values

Contract ID to calculate next billing date for: {!recordId}

Store Output Values - assign this to the variable you created in "Prerequisites" step 3.

Next Billing Date calculated by action: {!NextBillingDate}

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

Add a Decision element to validate whether the Next Billing Date returned by the Apex action is null.

 

Create a Next Billing Date is Null outcome and set the condition to:

{!NextBillingDate} Is Null {!$GlobalConstant.True}

Screenshot of Decision window in the Flow UI
6 Flow Element: Assignment

For the Next Billing Date is Null outcome, add an Assignment element and set the following assignment:
{!NextBillingDate} Equals {!$Flow.CurrentDate}

Note:

This means that if the Next Billing Date returned by the Apex action is null, it is automatically set to today's date.

Screenshot of Assignment window in the Flow UI
7 Flow Element: Create Records

Add a Create Records element and complete the window as follows:

How Many Records to Create: One

How to Set the Record Fields: Use separate resources, and literal values

Object: Billing Contract Line Item

Set Field Values for the Billing Contract Line Item

Field Value
ffbc__BillingType__c One-off
ffbc__Contract__c {!ChangeRequestId}
ffbc__Description__c {!Description}
ffbc__EndDate__c {!Credit_Period_End_Date}
ffbc__FirstBillDate__c {!NextBillingDate}
ffbc__ProductService__c {!Credit_Category.selectedChoiceValues}
ffbc__Quantity__c 1
ffbc__StartDate__c {!Credit_Period_Start_Date}
ffbc__UnitPrice__c {!Credit_Amount}
Note:

The values in this table will be used to create the service credit contract line item.

Screenshot of Create Records window in the Flow UI
8 Flow Element: Apex Action

Add an Action element. Choose the Apply Change Requests action, then complete the input and output values.

Set Input Values

Change Request ID to be applied: {!ChangeRequestId}
Disable creation of credit notes when applying the change request: {!$GlobalConstant.False}
Generate Billing Schedules using a batch job that runs asynchronously: {!$GlobalConstant.False}

Screenshot of New Action window in the Flow UI
9 Flow Element: Screen

Add a Screen element.

Enter a label for the screen: Credit Line Added Successfully

Add a Display Text component with the wording: Credit line added successfully.

Screenshot of Screen Component in Flow UI
10 Flow Element: End End of flow.  
  Activate the flow Remember to save and activate the flow to make it available for use.  
 

Link the screen flow to a new button on the billing contract header so that users can click it to invoke the flow.

To add a button for users to invoke the flow from a billing contract's detail page:

  1. In Object Manager, navigate to the Billing Contract object.

  2. In the Buttons, Links, and Actions section, click New Action.

  3. Set Action Type to Flow.

  4. In the Flow drop-down, select the flow you have created and activated.

  5. Enter a label for the button, such as Apply Service Credit. The name will default from the label.

  6. Save your changes.

Now add the action to the billing contract Lightning record page:

  1. Open the Contract Lightning Page in the Lightning App Builder.

  2. Select the Highlights Panel at the top of the page. The Actions included in this panel are listed in the properties pane.

  3. Add the action you have created.

  4. Save your changes.

If you do not use the Contract Lightning Page, you will need to add the action to your billing contract page layouts.

Note:

Make sure your users have the Run Flows permission enabled on their profile. Users will not be able to see the new button if they do not have this permission.