Skip to main content
Free Agentforce workshops and AI Certifications: Learn more. Terms and conditions apply.

Create a Flow for Purchases

Create a Flow for Base Points

As part of the accrual process, Linda creates a flow that calculates the points (qualifying and non-qualifying) to credit based on the tier and the transaction amount. She creates a record-triggered flow because she wants the flow to launch when a transaction journal is created. 

Note

Typically, the integrating system (POS, Commerce System, and so forth) creates the transaction journals and calls the Flow API to process transactions. 

Here’s what she does.

  1. Click Setup, and select Setup.
  2. Enter Flows in the Quick Find box, and select Flows.
  3. Click New Flow.
  4. Make sure Start from Scratch is selected, and click Next.
  5. Select Record-Triggered Flow.
  6. Click Create and provide the following details.
    • Object: Transaction Journal
    • Configure Trigger: A record is created
    • Condition Requirements: All Conditions are Met (AND)
    • Field: Status
    • Operator: Equals
    • Value: Pending
    • Optimize this flow for: Actions and Related Records
  1. Click Close to close the panel.

The Configure Start panel where you define the conditions for when the flow should run.

Select the Layout

In the button bar, change the Auto-Layout setting to Free-Form.

The Flow Builder setting where you select the layout.

Create the Resources

Before Linda can add the elements required to run this flow, she creates the resources that she will reference in the flow. 

  1. On the Manager tab, click New Resource.
  2. Provide the following details.
    • Resource Type: Variable
    • API Name: TransactionAmount
    • Data Type: Number
    • Decimal Places: 2
    • Default Value: select Triggering TransactionJournal, then Transaction Amount
  1. Click Done.
  2. Linda repeats steps 1 to 3 to create the remaining resources with the following details.

Resource Type

API Name

Data Type

Decimal Places

Default Value

Formula

Available for Input

Available for Output

Variable

Multiplier

Number

2

-

-

-

-

Formula

BasePointsToCredit

Number

2

-

{!TransactionAmount}*{!Multiplier}

-

-

The New Resource window where you create the variable for the transaction amount.

Define the Rules

Linda now adds all the elements required for the flow. She first uses a Decision element to filter all the transaction journals related to the Inner Circle loyalty program, with the journal subtype as Purchase. 

Note

Note

If you encounter an error after entering the value {!$Record.LoyaltyProgram.Name} in the Resource field, click inside the field and select the related object from the menu. Select $Record (TransactionJournal) > LoyaltyProgram (Loyalty Program ID) > Name (Program Name).

  1. On the Elements tab, drag the Decision element onto the canvas.
  2. For Label, enter CheckEntryConditions.
  3. Provide the following details.
    • Outcome Details Label: EntryConditions
    • Condition Requirements to Execute Outcome: All Conditions Are Met (AND)
    • Resource: select Triggering TransactionJournal, then Loyalty Program ID (the one with a > at the end of the line), then Program Name
    • Operator: Equals
    • Value: Cloud Kicks Inner Circle
    • Click Add Condition and provide the following details.

      Resource

      Operator

      Value

      Triggering TransactionJournal > Journal Type ID (the one with a > at the end of the line) > Program Name

      Equals

      Accrual

      Triggering TransactionJournal > Journal Subtype ID (the one with a > at the end of the line) > Program Name

      Equals

      Purchase
  1. Click Done.

The New Decision window where you define the parameters to filter the transactions.

She then uses the Action element to get details of member tiers. 

  1. On the Elements tab, drag the Action element onto the canvas, and provide the following details.
    • Filter by: Loyalty
    • Action: Get Tier
    • Label: GetCurrentTier
    • Program: Cloud Kicks Inner Circle
    • Tier Group: Inner Circle Tier Group
    • Member ID: $Record > MemberId
  1. Click Done.

The New Action window where you enter values related to the program tier.

Next, she adds another Decision element. This evaluates which tiers the members belong to. 

  1. Drag the Decision element onto the canvas.
  2. For Label, enter CheckCurrentTier.
  3. Provide the following details.
    • Outcome Details Label: PlatinumAndDiamond
    • Condition Requirements to Execute Outcome: Any Condition Is Met (OR)
    • Resource: Outputs from GetCurrentTier > TierName
    • Operator: Equals
    • Value: Platinum
    • Click Add Condition.
    • Resource: Outputs from GetCurrentTier > TierName
    • Operator: Equals
    • Value: Diamond
  1. Click the New Outcome icon (New Outcome) and provide the following details.
    • Outcome Details Label: GoldAndSilver
    • Condition Requirements to Execute Outcome: Any Condition Is Met (OR)
    • Resource: Outputs from GetCurrentTier > TierName
    • Operator: Equals
    • Value: Gold
    • Click Add Condition.
    • Resource: Outputs from GetCurrentTier > TierName
    • Operator: Equals
    • Value: Silver
  1. Click Done.

The New Decision window where you define the parameters to check the members’ tier.

Linda then adds the Assignment element to assign a value to the variable. This element assigns the multiplier resource to each tier. Depending on which tier the member falls in, the points get multiplied. For example, if the member belongs to the Platinum tier, the system multiples the transaction amount by 2. 

  1. Drag the Assignment element onto the canvas and provide the following details.
    • Label: MultiplierForPlatinumAndDiamond
    • Variable: Multiplier
    • Operator: Equals
    • Value: 2
  1. Click Done.
  2. Repeat steps 1 and 2 to add an Assignment element for the other outcome with the following details.
    • Label: MultiplierForGoldAndSilver
    • Variable: Multiplier
    • Operator: Equals
    • Value: 1

The New Assignment window where you set the variable values.

Credit Qualifying and Non-qualifying Points

Linda adds action elements to the flow so that both qualifying and non-qualifying points get credited to members.

  1. On the Elements tab, drag the Action element onto the canvas, and provide the following details.
    • Filter by: Loyalty
    • Action: Credit Points
    • Label: CreditNonQualifyingPoints
    • Program: Cloud Kicks Inner Circle
    • Currency Type: Regular Points
    • Recipient Member ID: $Record > MemberId
    • Number of Points to Credit: BasePointsToCredit
    • Journal ID: $Record > Id
  1. Click Done.
  2. Repeat steps 1 and 2 with the following values.
    • Filter by: Loyalty
    • Action: Credit Points
    • Label: CreditQualifyingPoints
    • Program: Cloud Kicks Inner Circle
    • Currency Type: Tier Points
    • Recipient Member ID: $Record > MemberId
    • Number of Points to Credit: $Record > TransactionAmount
    • Journal ID: $Record > Id

The New Action window where you enter values required to credit points.

Put the Flow Together

Linda must now connect all the elements using connectors to build the flow. This determines the order in which the flow is executed at run time.

  1. Connect the elements in the following sequence.
    • The Start element to CheckEntryConditions (Decision)
    • CheckEntryConditions (Decision) to GetCurrentTier (Action), with the outcome selection being EntryConditions
    • GetCurrentTier (Action) to CheckCurrentTier (Decision)
    • CheckCurrentTier (Decision) to the two assignment elements MultiplierForPlatinumAndDiamond and MultiplierForGoldAndSilver, with outcome selections being PlatinumAndDiamond and GoldAndSilver respectively
    • The two Assignment elements to CreditNonQualifyingPoints (Action)
    • CreditNonQualifyingPoints (Action) to CreditQualifyingPoints (Action)
  1. Click Save.
  2. Enter the Flow Label: InnerCircleAccrualFlow
  3. Click Save.
  4. Click Activate.

The Flow Builder page where you add the required elements and connect them.

This flow will run every time a transaction journal record is created. The flow will check the tier that the member belongs to, calculate the points based on the tier, and credit the qualifying and non-qualifying points.

Create a Transaction Journal

Let’s look at how points are credited and updated when a transaction is processed. 

Adria Darby, a Platinum tier member, purchases a pair of shoes for $100. As soon as the transaction journal is created, Adria is credited with 200 non-qualifying points and 100 qualifying points. Linda creates a transaction journal to see this in action. 

  1. In the Loyalty Programs tab, select the Cloud Kicks Inner Circle loyalty program.
  2. In the Cloud Kicks Inner Circle program record, click the Members And Partners tab.
  3. In the Loyalty Program Members related list, select CL001.
  4. On the Transaction Journals card, click New.
  5. Provide the following details.
    • Journal Type: Accrual
    • Journal Subtype: Purchase
    • Activity Date: Current Date
    • Journal Date: Current Date
    • Status: Pending
    • Loyalty Program: Cloud Kicks Inner Circle
    • Transaction Amount: 100
  1. Click Save.

The New Transaction Journal window where you can manually create a transaction journal.

As soon as the record is created, the transaction journal status changes to Processed, and the Loyalty Ledgers card is updated with the points. 

The Loyalty Ledgers card where you can see the credited points.

Linda navigates to the member’s record and in the Loyalty Member Currency card, she sees the non-qualifying and qualifying points balance updated. Note that you may need to refresh your page to see the updated points.

We’ve created a flow for purchases. In the next step, we’ll create an accrual flow for engagement activities. 

Share your Trailhead feedback over on Salesforce Help.

We'd love to hear about your experience with Trailhead - you can now access the new feedback form anytime from the Salesforce Help site.

Learn More Continue to Share Feedback