Sample Flow to Apply a Change Request on Approval

This page describes a sample flow to automatically apply a change request once its Approval Status changes to "Approved".

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 any credit note that is created when the change request is applied. Name this variable CreditNoteId.

    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 error messages. Name this variable ApplyChangeRequestErrorMessage.

    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 action. Name this variable ApplyChangeRequestHasErrors.

    Screenshot of New Resource window in the Flow UI

The Sample Flow

This sample flow is a is a Record-Triggered Flow that uses the Apply Change Requests action. There are three outcomes: a success outcome, a success outcome with a draft credit note created, and an error outcome. If a draft credit note is created or an error occurs, the flow notifies the user via a Salesforce task.

Diagram of Sample Flow to Apply Change Request

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 Record-Triggered flow. In the Configure Start window, set:

Object: Billing Contract

Trigger the Flow When: A record is updated

Condition requirements: All conditions are met (AND)

Then add the following conditions:

ffbc__Type__c Equals Change Request

ffbc__ApprovalStatus__c Equals Approved

When to Run the Flow for Updated Records: Only when a record is updated to meet the condition requirements

Screenshot of Configure Start window in the Flow UI
2 Flow Element: Apex Action

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

Note:

For more information about the following parameters, see Custom Action to Apply Change Requests.

Set Input Values

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

Store Output Values - assign these to the variables you created in "Prerequisites".

Credit Note ID created by applying this change request: {!CreditNoteId}

Error while applying this change request:{!ApplyChangeRequestErrorMessage}
Has Errors: {!ApplyChangeRequestHasErrors}

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

Add a Decision element to check for the results of the action.

 

Create a Has Errors outcome for if the Apex action returns an error. The condition for this outcome is:

ApplyChangeRequestHasErrors Equals True

 

Create a Draft Credit Note Created outcome for if the Apex action creates a draft credit note when applying the change request. The condition for this outcome is:

CreditNoteId Is Null False

Screenshot of New Decision window in the Flow UIScreenshot of New Decision window in the Flow UI
4 Flow Element: Action For the Has Errors outcome, add a New Task action then complete the input values.

Set Input Values

Assigned To ID: {!$User.Id}
Related Record ID: {!$Record.Id}
Subject: Applying a change request has failed: {!ApplyChangeRequestErrorMessage}

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

For the Draft Credit Note Created outcome, add a Get Records element. In the Get Records window, set:

Object: Billing Document

Condition requirements: All conditions are met (AND)

Then add the following condition:

Id Equals CreditNoteId

 

Screenshot of New Action window in the Flow UI
6 Flow Element: Action Next for the Draft Credit Note Created outcome, add a New Task action then complete the input values.

Set Input Values

Assigned To ID: {!$User.Id}
Related Record ID: {!CreditNoteId}
Subject: A credit note {!Get_credit_note.Name} has been created automatically

Screenshot of New Action window in the Flow UI
7 Flow Element: End The Has Errors outcome, the Draft Credit Note Created outcome, and the default outcome are now ended. The Flow Builder might display the three 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.