Order Finaliser Flow
Note
This flow is self-documenting and should be viewed within Salesforce (Setup -> Process Automations -> Flows).\ This document is to support working through a visual flow. Please Note: The flow commentary is produced using AI.
Overview
- Flow Name: MoveData_Commerce_Order_Final
- Label: [MoveData] Commerce: Order - Finaliser
- Type: Auto-Launched Flow Template
- API Version: 56.0
- Status: Active
This flow handles comprehensive post-processing operations after commerce order records are created or updated, including stage finalization, dynamic order naming, amount calculation with fee deduction, and campaign member creation for commerce transactions.
Purpose
The flow performs post-upsert operations that:
- Finalize opportunity stage assignment from default to "Closed Won" for completed orders
- Generate dynamic order names using configurable patterns for contacts and accounts
- Handle temporary amount assignment for name parsing when amounts are not set
- Create campaign member records for customers with commerce-specific or ticket-based status management
- Support action-based campaign member labeling (ticket vs general commerce)
- Clear temporary fields after processing to maintain data integrity
Salesforce Fields
This flow interacts with the Salesforce Opportunity object and its related fields. Below is a mapping of all fields utilized:
| Field API Name | Field Type | Purpose in Flow |
|---|---|---|
| Id | ID | Unique record identifier |
| Name | Text (120) | Order name using dynamic patterns |
| StageName | Picklist | Order stage finalization |
| Amount | Currency | Order total with fee calculations |
Input Variables
Core Order Data
| Variable | Type | Required | Description |
|---|---|---|---|
Record |
Opportunity SObject | Yes | The Opportunity record that was processed |
OrderName |
String | No | Order name from external platform |
Action |
String | No | Order action type (e.g., "ticket") |
Code |
String | No | Order code identifier |
Description |
String | No | Order description |
CreatedAt |
DateTime | No | Order creation timestamp |
PlatformKey |
String | No | Platform key for tracking |
Related Records
| Variable | Type | Description |
|---|---|---|
PrimaryContact |
Contact SObject | Primary contact for the order |
PrimaryAccount |
Account SObject | Associated account for the order |
OrderCampaign |
Campaign SObject | Associated campaign |
Fee Structure
| Variable | Type | Description |
|---|---|---|
Total |
Currency | Order total amount |
FeePlatform |
Currency | Platform processing fee |
Campaign Member Configuration
| Variable | Type | Default | Description |
|---|---|---|---|
Config_CreateCampaignMembers |
Boolean | true | Enable campaign member creation |
Config_CampaignMemberDeleteExistingStatuses |
Boolean | false | Remove existing campaign member statuses |
Config_CampaignMemberLabelTeamLeader |
String | "Team Leader" | Label for team leader status |
Config_CampaignMemberLabelFundraiser |
String | "Fundraiser" | Label for fundraiser status |
Config_CampaignMemberLabelRecurringDonor |
String | "Recurring Donor" | Label for recurring donor status |
Config_CampaignMemberLabelCommerce |
String | "Sale" | Label for commerce status |
Config_CampaignMemberLabelTicket |
String | "Ticket Holder" | Label for ticket holder status |
Config_CampaignMemberLabelProspect |
String | "Prospect" | Label for prospect status |
Processing Variables
| Variable | Type | Default | Description |
|---|---|---|---|
Config_OrderStageNameDefault |
String | "Prospecting" | Default stage name for orders |
Config_OrderTotalSubtractFeePlatform |
Boolean | false | Subtract platform fees from order total |
Config_OrderNameContact |
String | (ASCII) | Naming pattern for contact-based orders |
Config_OrderNameAccount |
String | (ASCII) | Naming pattern for account-based orders |
CampaignIdList |
String[] | - | List of campaign IDs for member creation |
Output Variables
| Variable | Type | Description |
|---|---|---|
Record |
Opportunity SObject | Updated opportunity record |
Errors |
String[] | Collection of error messages |
Logs |
MoveDataLogEntry[] | Processing logs from all operations |
LogsJSON |
String | JSON representation of processing logs |
Flow Logic
1. Stage Finalization
-
Default Stage Detection:
-
Checks if current StageName equals
Config_OrderStageNameDefault("Prospecting") - Updates stage to "Closed Won" for completed commerce orders
- Preserves existing stages that have been explicitly set
2. Dynamic Order Naming
-
Name Processing Decision:
-
Proceeds with naming only if Name is null or equals "Temp Value"
-
Logs order record details for audit purposes
-
Customer Type Resolution:
-
Contact-Based Naming: When PrimaryAccount is null, uses contact naming pattern
-
Account-Based Naming: When PrimaryAccount exists, uses account naming pattern
-
Naming Pattern Selection:
For Contact-Based Orders:
- Uses
Config_OrderNameContactif configured - Falls back to default contact pattern:
{!Contact.Name} {!CloseDate} {!Amount} {!RecordType.Name}
For Account-Based Orders:
- Uses
Config_OrderNameAccountif configured - Falls back to default account pattern:
{!Account.Name} {!CloseDate} {!Amount} {!RecordType.Name}
3. Amount Processing for Naming
- Temporary Amount Assignment:
When Amount is not set on the record:
- Calculates temporary amount using fee deduction formula
- Sets amount temporarily for name parsing
-
Flags for cleanup after name generation
-
Amount Calculation Formula:
CalculatedTotal = IF(Config_OrderTotalSubtractFeePlatform, DefaultedTotal - DefaultedFeePlatform, DefaultedTotal)
-
Field Cleanup:
-
Removes Amount field from record after name parsing when temporarily set
- Uses
ClearFieldFlowComponentto maintain data integrity - Prevents unintended amount assignment
4. Order Name Generation
-
Pattern Parsing:
-
Uses
NamePatternParserComponentwith configurable format strings - Supports Contact and Account reference merging
- Handles missing name scenarios with temporary placeholder
- Provides detailed error handling for pattern parsing failures
5. Campaign Member Management
-
Prerequisites Validation:
-
Campaign exists with valid ID
- Contact exists with valid ID
-
Campaign member creation is enabled
-
Action-Based Status Assignment:
-
Ticket Action: Uses "Ticket Holder" status with ticket-specific sort order
-
Default Commerce: Uses "Sale" status with general commerce sort order
-
Campaign Member Status Initialization:
InitialiseCampaignMemberComponent Parameters:
- CampaignId: OrderCampaign.Id
- DeleteOtherCampaignMemberStatuses: Config setting
- Status Labels: All configurable member status labels with commerce-specific defaults
- Hierarchical Status Management:
The flow establishes a prioritized hierarchy:
- Team Leader (highest priority)
- Fundraiser
- Recurring Donor
- Commerce/Ticket Holder (target status for this flow)
-
Prospect (lowest priority)
-
Sort Order Configuration:
-
Commerce Status: Sort order 9011
- Ticket Holder Status: Sort order 9012
6. Campaign Member Value Hierarchy Setup
The flow establishes the complete campaign member status hierarchy:
- Team Leader
- Fundraiser
- Recurring Donor
- Commerce (Sale/Ticket Holder)
-
Prospect
-
Campaign Member Creation:
-
Uses
NpspCreateCampaignMemberProxyfor NPSP integration - Respects existing higher-priority statuses
- Upgrades lower-priority statuses appropriately
Error Handling
Name Processing Protection
- Uses fault connector for name parsing failures
- Falls back to "Temp Value" when name generation fails
- Maintains processing continuity despite naming errors
Amount Field Management
- Tracks temporary amount assignment with boolean flag
- Ensures proper cleanup of temporary fields
- Prevents data corruption from incomplete processing
Campaign Member Validation
- Validates all required relationships before processing
- Handles missing campaign or contact scenarios gracefully
- Provides detailed logging for troubleshooting
Dependencies
Apex Components
- movedata__ClearFieldFlowComponent: Field cleanup for temporary values
- movedata__WriteObjectToLogComponent: Order record logging
- movedata__NamePatternParserComponent: Dynamic name generation
- NpspInitialiseCampaignMemberProxy: Campaign member status setup
- NpspCreateCampaignMemberProxy: Campaign member creation with hierarchy support