Skip to content

Flow Name: Populate discount code on Order

Last Updated: 2024-10-29 Source Code: Populate_discount_code_on_Order.flow-meta.xml

API Name: Populate_discount_code_on_Order Status: Active Type: Custom Trigger: After Save on OrderItemAdjustmentLineItem record creation

Business Purpose

Automatically populates the discount code field on Order records when order item adjustments are applied, enabling proper tracking and reporting of discount usage across orders.

Process Flow

  1. Coupon Lookup: Retrieves Coupon record using AdjustmentBasisReferenceId from the adjustment line item
  2. Order Item Lookup: Gets related OrderItem record using OrderItemId from the adjustment
  3. Data Validation: Checks if both coupon and order item data exist
  4. Order Update: Updates the parent Order's Discount_Code__c field with the coupon code
📊 Click to view Process Flow Diagram
flowchart TD
    Start([Start: After Save on OrderItemAdjustmentLineItem record creation]) --> Lookup[Lookup Related Data]

    Lookup --> Found{Data<br/>Found?}
    Found -->|No| End([End])
    Found -->|Yes| Calculate[Calculate/Determine Values]

    Calculate --> Update[Update Records]
    Update --> End

    style Start fill:#e1f5ff
    style Lookup fill:#f0e1ff
    style Found fill:#fff4e1
    style Calculate fill:#e1ffe1
    style Update fill:#ffe1e1
    style End fill:#e1f5ff

Key Business Rules

  • Triggers only on creation of OrderItemAdjustmentLineItem records
  • Requires valid AdjustmentBasisReferenceId linking to a Coupon record
  • Updates parent Order record via OrderItem relationship chain
  • Single coupon code per order (subsequent adjustments overwrite previous codes)

Dependencies

  • OrderItemAdjustmentLineItem object with fields: AdjustmentBasisReferenceId, OrderItemId
  • Coupon object with field: CouponCode
  • OrderItem object with field: OrderId
  • Order object with custom field: Discount_Code__c

Changes

No specific PR references found in flow description

⚠️ Pre-Go-Live Concerns

CRITICAL - Fix Before Go-Live

  • Custom Field Dependency: Order.Discount_Code__c field must exist or flow will fail

HIGH - Address Soon After Go-Live

  • Error Handling: No error handling if coupon or order item lookups fail
  • Multiple Discounts: Last discount code overwrites previous ones on same order
  • Invalid References: No validation if AdjustmentBasisReferenceId points to invalid coupon

MEDIUM - Future Enhancement

  • Add error handling for failed lookups and invalid data
  • Consider concatenating multiple discount codes instead of overwriting
  • Add validation that adjustment actually represents a discount
  • Implement audit trail for discount code applications

LOW - Monitor

  • Performance impact of synchronous order updates
  • Frequency of discount code overwrites
  • Data consistency between adjustments and order discount codes

Maintenance Notes

Simple flow but critical for discount tracking. Monitor for failed updates due to missing custom fields or invalid coupon references. Consider whether multiple discount codes per order should be supported or if current overwrite behavior is intended.