Skip to content

Flow Name: Populate Promotion On the Order Product

Last Updated: 2025-06-09 Source Code: Populate_Promotion_On_the_Order_Product.flow-meta.xml

API Name: Populate_Promotion_On_the_Order_Product Status: Active Type: Custom Trigger: After OrderItem save (Create and Update)

Business Purpose

Manages promotion application to OrderItem records by detecting promotions applied manually vs. through web portal, validating promotion eligibility, creating adjustment line items, and updating product descriptions. This flow bridges manual promotion management with automated web-based promotions.

Process Flow

  1. Promotion Source Detection: Determines if promotion was applied manually or via web portal
  2. Existing Adjustment Check: Looks for existing OrderItemAdjustmentLineItem records
  3. Manual Path: If manually applied promotion exists:
  4. Validates promotion record exists
  5. Retrieves promotion targets and coupon information
  6. Loops through targets to check product/category eligibility
  7. Creates adjustment line items based on promotion type (fixed amount vs percentage)
  8. Web Portal Path: If web-applied promotion:
  9. Finds CartItemPriceAdjustment records
  10. Extracts promotion ID and applies to OrderItem
  11. Error Handling: Updates OrderItem description with error message if promotion is ineligible
  12. Cleanup: Removes description field content after processing
📊 Click to view Process Flow Diagram
flowchart TD
    Start([Start: After OrderItem save (Create and Update)]) --> 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

  • Manual Promotions: Applied via Promotions__c field on OrderItem
  • Web Promotions: Auto-detected from Order_Source__c = "Submitted via the web"
  • Eligibility Validation: Checks promotion targets against Product2Id or ProductCategory
  • Adjustment Types Supported:
  • FixedAmountOffUnitPrice: Creates fixed amount adjustment
  • PercentageDiscount: Creates percentage-based adjustment
  • Other types skip adjustment creation
  • Error Messaging: Sets OrderItem description for ineligible promotions
  • Single Processing: Uses flag to prevent duplicate adjustment creation

Dependencies

  • OrderItem object with Promotions__c field
  • Order object with Order_Source__c field
  • Promotion, PromotionTarget, Coupon objects
  • OrderItemAdjustmentLineItem object for creating price adjustments
  • ProductCategory object for category-based promotions

Changes

No specific PR notes found in metadata

⚠️ Pre-Go-Live Concerns

CRITICAL - Fix Before Go-Live

  • Complex Decision Logic: Flow has 13+ decision points creating multiple execution paths that are difficult to test comprehensively
  • Missing Null Validation: No checks if Promotion, PromotionTarget, or Coupon lookups fail
  • Hardcoded String Matching: Relies on exact match for "CartItemPriceAdjustment" and "Submitted via the web" - case-sensitive

HIGH - Address Soon After Go-Live

  • Performance Issues: Multiple loops within loops could cause CPU timeout on large orders with many promotion targets
  • Incomplete Error Handling: Some paths lack fault connectors, flow could fail silently
  • Promotion Type Coverage: Only handles 2 of 6+ adjustment types, others are ignored without notification

MEDIUM - Future Enhancement

  • Magic Numbers: Uses hardcoded -1 multiplier for adjustments instead of configurable logic
  • Description Management: Overwrites OrderItem.Description field which may contain other important data
  • Category Lookup: Gets category name but doesn't validate category hierarchy or active status

LOW - Monitor

  • Variable Naming: Some inconsistent naming conventions (appliedWebPromotionId vs categoryName)
  • Label Typos: "Pormotion" in interviewLabel should be "Promotion"
  • Unused Paths: Several decision outcomes lead nowhere, indicating incomplete implementation

Maintenance Notes

Complexity: Very High - This flow is extremely complex with nested loops, multiple decision trees, and intricate business logic. Changes require extensive testing across all promotion types and scenarios. The dual-path logic (manual vs web) makes troubleshooting difficult. Recommended bi-monthly review with promotion team and quarterly full regression testing. Consider breaking into smaller, more focused flows for better maintainability.