Skip to content

Flow Name: Update the Line Product Name on Order After Activation

Last Updated: 2025-10-22 Source Code: Update_the_Line_Product_Name_on_Order_After_Activation.flow-meta.xml

API Name: Update_the_Line_Product_Name_on_Order_After_Activation Status: Active Type: Custom Trigger: Record-Triggered Flow - After Save on Order (Update only)

Business Purpose

This flow automatically updates the Line_Product_Name__c field on an Order record with the name of a product from the associated Order Items. This provides a quick reference to products on the order without needing to query related Order Items.

Process Flow

  • Queries OrderItem records where OrderId equals the current Order's ID
  • Retrieves all Order Items associated with the activated order

2. Validation Check

  • Verifies that Order Items were found
  • If no Order Items exist, flow exits without action

3. Loop Through Order Items

  • Iterates through each Order Item in the collection
  • For each Order Item, assigns the Product2.Name to a variable
  • Note: Variable is overwritten in each iteration, capturing the last product name

4. Update Order Record

  • Updates the current Order record's Line_Product_Name__c field
  • Sets the field to the product name from the loop variable
📊 Click to view Process Flow Diagram
flowchart TD
    Start([Start: Order Updated<br/>Status=Activated<br/>Line_Product_Name=N/A]) --> GetItems[Get Order Items<br/>for Order]

    GetItems --> CheckItems{Order Items<br/>Found?}
    CheckItems -->|No| End([End])

    CheckItems -->|Yes| LoopItems[Loop Through<br/>Order Items]
    LoopItems --> AssignName[Assign Product Name<br/>to Variable<br/>Overwrites Each Iteration]

    AssignName --> UpdateOrder[Update Order<br/>Line_Product_Name__c]
    UpdateOrder --> End

    UpdateOrder -->|Error| ShowError[Display Error Message<br/>with Fault Details]
    ShowError --> End

    style Start fill:#e1f5ff
    style GetItems fill:#f0e1ff
    style CheckItems fill:#fff4e1
    style LoopItems fill:#e1ffe1
    style AssignName fill:#ffe1e1
    style UpdateOrder fill:#ffe1e1
    style ShowError fill:#ffcccc
    style End fill:#e1f5ff

Key Business Rules

  • Only triggers when Order Status = "Activated" AND Line_Product_Name__c = "N/A"
  • Evaluation criteria: Record is changed to meet criteria (not every update)
  • Loops through ALL Order Items but variable is overwritten each iteration
  • Logic Flaw: Captures the LAST product name from loop, not necessarily the first or most important
  • Provides custom error message with fault details if update fails
  • No error handling for missing Order Items (flow simply exits)

Dependencies

  • Order object with custom field: Line_Product_Name__c
  • OrderItem object with proper relationships
  • Product2 object with Name field

Changes

No specific pull requests or changes noted in the flow metadata.

Pre-Go-Live Concerns

CRITICAL - Fix Before Go-Live

  • Fix loop logic to capture first product name instead of last (add getFirstRecordOnly=true to query or break after first iteration)
  • Add proper sorting to ensure consistent product selection (e.g., sort by CreatedDate or OrderItem Id)
  • Define business rules for which product to use when multiple Order Items exist

HIGH - Address Soon After Go-Live

  • Optimize query to retrieve only first Order Item if only one product name is needed
  • Add business logic to select the "primary" or most important product if multiple exist
  • Consider implementing product hierarchy or priority logic

MEDIUM - Future Enhancement

  • Evaluate if this field is actually needed or if reports can query OrderItems directly
  • Consider using a formula field instead of a flow for better performance
  • Add support for concatenating multiple product names if business requires it
  • Implement the logic in a trigger for more complex business rules

LOW - Monitor

  • Track orders with multiple Order Items to understand product selection impact
  • Monitor for orders not getting Line_Product_Name__c populated
  • Verify that the "last" product selected is acceptable for business reporting

Maintenance Notes

  • Complexity: Low-Medium - simple logic but has a critical flaw in loop implementation
  • Critical Issue: Loop overwrites variable in each iteration, resulting in unpredictable product name selection
  • Variables: var_lineProductName (String) stores the product name
  • Performance impact: Queries and loops through all Order Items even when only one name is needed
  • Review immediately to fix loop logic issue before production use
  • Test with single and multiple Order Item scenarios to verify expected behavior