Loading
Data Processing Engine
Create a Definition to Calculate Purchase Credit and Reward

Create a Definition to Calculate Purchase Credit and Reward

The Cloud Kicks admin created and activated a Data Processing Engine definition to calculate and update the purchase credit for accounts based on their orders. The definition is also used to calculate the bonuses to be awarded to the salespeople associated with the orders.

Required Editions

View supported editions.

The admin uses Order and Contact as the data source objects. The purchase credit for accounts is written back to a custom field in the Account object, and the employee bonus is written back to the custom object Salesperson Bonus. The definition uses two input variables to ensure that the orders that were effective and closed during a specific financial year are considered. The input variable values aren't defined, and the admin wants to define the dates every time the definition runs in Flows.

The admin defines the definition as:

  • Name: Calculate Purchase Credit and Bonus
  • API Name: Calculate_Purchase_Credit_and_Bonus
  • Process Type: Standard

Here's how the admin defined each node in the definition along with the input variables. The sequence that the nodes are created in is also specified.

1. Select Data Sources

The admin selects two data source objects and the required fields from each object.

Node Type Node Name Object Node Configuration
Data Source Order Order

Selected fields:

  • AccountId
  • EffectiveDate
  • EndDate
  • Id
  • OwnerId
  • Status
  • TotalAmount
Data Source User User

Selected fields:

  • Email
  • Id

The admin requires only these two objects as data sources and not the Account object because the AccountId is a related field of the Order object.

Order data source node

2. Create Input Variables

To filter Order records that were placed and fulfilled during a particular year, two filter variables are required.

Input Variable Name Type
OrderEffectiveDate Date
OrderEndDate Date

The values for both input variables aren't defined because the admin wants to define the values based on the year when the definition is run.

OrderCreatedDate input variable

3. Filter Orders

Next, the admin creates a Filter node that filters out Order records with effective dates that were closed during the year.

Node Type Node Name Source Node Node Configuration
Filter Filter Orders Order
  • Filter conditions: All conditions are met (AND)
  • First filter condition:
    • Field: EffectiveDate
    • Operator: Greater Than or Equal
    • Type: Input Variable
    • Value: OrderEffectiveDate
  • Second filter condition:
    • Field: EndDate
    • Operator: Less Than or Equal
    • Type: Input Variable
    • Value: OrderEndDate
  • Third filter condition:
    • Field: Status
    • Operator: Equals
    • Type: Field
    • Value: Activated

Filter orders in Filter node.

4. Join Order and Contact

The admin joins the two tables to use only the data for the filtered orders and the associated users. The admin selects the Join Type as Inner to ensure that only the records for salespeople associated with the orders are included in the joined dataset.

Node Type Node Name Source Nodes Node Configuration
Join Join Filtered Orders and Users
  • First Source Node: Filter Order
  • Second Source Node: User
  • Selected Fields in First Source Node
    • AccountId (Alias: OrderAccountId)
    • TotalAmount (Alias: OrderTotalAmount)
  • Selected Fields in Second Source Node
    • Email (UserEmail)
    • Id (Alias: UserId)
  • Map Fields:
    • First Node Field: OwnerId
    • Second Node Field: Id

Join filtered order and user in Join node.

5. Group by Account and Aggregate Total Amount

The admin creates a node that groups the orders by account and calculates the sum of the order amounts of all the filtered orders associated with each account.

Node Type Node Name Source Node Node Configuration
Group and Aggregate Group by Account and Sum Total Amount Join Filtered Orders and Users
  • Group field: OrderAccountId
  • Aggregate:
    • Alias: AccountTotalOrderAmount
    • Function: Sum
    • Field: OrderTotalAmount

Group by AccountId and aggregate sum by total order amount.

6. Group by User and Aggregate Total Amount

The admin creates another similar node. This node groups the orders by the associated user and calculates the sum of the order amounts of all the filtered orders associated with each user.

Node Type Node Name Source Node Node Configuration
Group and Aggregate Group by User and Sum Total Amount Join Filtered Orders and Users
  • Group fields:
    • UserEmail
    • UserId
  • Aggregate:
    • Alias: UserTotalOrderAmount
    • Function: Sum
    • Field: OrderTotalAmount

7. Calculate Purchase Credit for Accounts

To calculate the purchase credit amount, this formula uses the sum calculated in the Group by Account and Sum Total Amount node.

Node Type Node Name Source Node Node Configuration
Formula Purchase Credit Amount Group by Account and Sum Total Amount
  • Alias: PurchaseCreditAmount
  • Field Type: Number
  • Length: 10
  • Decimal Places: 2
  • Formula: {AccountTotalOrderAmount} / 20

Calculate purchase credit amount in a Formula node.

8. Calculate Bonus for Users

To calculate the bonus amount this formula uses the sum calculated in the Group by User and Sum Total Amount node.

Node Type Node Name Source Node Node Configuration
Formula Bonus Amount Group by User and Sum Total Amount
  • Alias: BonusAmount
  • Field Type: Number
  • Length: 10
  • Decimal Places: 2
  • Formula: {UserTotalOrderAmount} / 200

9. Write Back Purchase Credit for Accounts

In this step, a Writeback Object node is created to write back the Purchase Credit Amount to the Purchase Credit custom field on the Account object.

Node Type Node Name Source Node Node Configuration
Writeback Objects Update Purchase Credit for Accounts Purchase Credit Amount
  • Action Type: Update
  • Target Object: Account
  • User with Writeback Permission: Cloud Kicks Admin
  • Writeback Sequence: 1
  • Update changed records only: Selected
  • Field Mappings:
    • First Field Mapping:
      • Source Node Field: OrderAccountId
      • Target Field: Id
    • Second Field Mapping:
      • Source Node Field: PurchaseCreditAmount
      • Target Field: PurchaseCreditAmount__c

Write back to Year End Purchase Credit custom field in the Account object

10. Write Back Salesperson Bonus Amount

In this last step, a Writeback Object node is created to write back the bonus amount and the other employee details to the Salesperson Bonus custom object.

Node Type Node Name Source Node Node Configuration
Writeback Objects Update Bonus for Salespeople Bonus Amount
  • Action Type: Insert
  • Target Object: User
  • User with Writeback Permission: Cloud Kicks Admin
  • Writeback Sequence: 2
  • Field Mappings:
    • First Field Mapping:
      • Source Node Field: UserId
      • Target Field: SalespersonId__c
    • Second Field Mapping:
      • Source Node Field: BonusAmount
      • Target Field: Bonus_Amount__c
    • Third Field Mapping:
      • Source Node Field: UserEmail
      • Target Field: SalespersonEmail__c

The Writeback Object node with Salesperson Bonus as writeback object.

 
Loading
Salesforce Help | Article