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. The flow commentary in this document was generated with AI assistance.
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 manages post-processing tasks after commerce orders are created or updated, including stage finalisation, dynamic order naming, amount calculation with fee deduction, and campaign member creation.
Purpose#
The flow performs post-upsert operations that:
- Finalise 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 labelling (ticket vs general commerce)
- Clear temporary fields after processing to maintain data integrity
Salesforce fields#
| 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 finalisation |
| 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 |
PrimaryContactAlt |
Account SObject | Person Account alternative |
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 |
Naming configuration#
| Variable | Type | Default | Description |
|---|---|---|---|
Config_OrderStageNameDefault |
String | "Prospecting" | Default stage name for orders |
Config_OrderExcludeFeePlatform |
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 |
Campaign member sort orders#
| Variable | Type | Default | Description |
|---|---|---|---|
Config_CampaignMemberSortOrderCommerce |
Number | 9011.0 | Sort order for commerce status |
Config_CampaignMemberSortOrderTicket |
Number | 9012.0 | Sort order for ticket status |
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 finalisation#
- 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 using
WriteObjectToLogComponentfor audit purposes
Customer type resolution:
- Contact-based naming: When PrimaryContact or PrimaryContactAlt exists
- Account-based naming: When neither contact option exists, defaults to account
Naming pattern selection:
For contact-based orders:
- Uses
Config_OrderNameContactif configured and not blank - Falls back to default contact pattern (ASCII encoded):
{!Contact.Name} {!CloseDate} {!Amount} {!RecordType.Name}
For account-based orders:
- Uses
Config_OrderNameAccountif configured and not blank - Falls back to default account pattern (ASCII encoded):
{!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
CalculatedTotalformula - Sets amount temporarily for name parsing
- Flags
TempSetAmountfor cleanup after name generation
Amount calculation formulas:
DefaultedTotal = IF(ISBLANK(Total), 0, Total)
DefaultedFeePlatform = IF(ISBLANK(FeePlatform), 0, FeePlatform)
CalculatedTotal = IF(Config_OrderExcludeFeePlatform==TRUE, DefaultedTotal - DefaultedFeePlatform, DefaultedTotal)
Field cleanup:
- Removes Amount field from record after name parsing when
TempSetAmountis true - Uses
ClearFieldFlowComponentto maintain data integrity - Prevents unintended amount assignment
4. Order name generation#
Pattern parsing:
Uses NamePatternParserComponent with different approaches:
- Standard contact/account processing: Supports Contact and Account reference merging; uses PrimaryContact and PrimaryAccount for standard relationships
- Person Account processing: Uses PrimaryContactAlt for Person Account scenarios; maps Person Account as both Contact and Account references
Error handling:
- Provides fault connectors for pattern parsing failures
- Falls back to "Temp Value" when name generation fails
- Uses
Missing_Namedecision for recovery scenarios
5. Campaign member management#
Prerequisites validation:
- Campaign exists with valid ID
- Contact exists with valid ID
- Campaign member creation is enabled (
Config_CreateCampaignMembers = true)
Action-based status assignment:
Ticket action:
- Sets status to
Config_CampaignMemberLabelTicket("Ticket Holder") - Uses
Config_CampaignMemberSortOrderTicket(9012.0)
Default commerce:
- Uses
Config_CampaignMemberLabelCommerce("Sale") - Uses
Config_CampaignMemberSortOrderCommerce(9011.0)
Campaign member status hierarchy:
The flow establishes a prioritised hierarchy:
| Priority | Status |
|---|---|
| 1 | Team Leader |
| 2 | Fundraiser |
| 3 | Recurring Donor |
| 4 | Commerce/Ticket Holder |
| 5 | Prospect |
Constants#
Naming pattern constants#
- OrderNameContact: ASCII-encoded string representing
{!Contact.Name} {!CloseDate} {!Amount} {!RecordType.Name} - OrderNameAccount: ASCII-encoded string representing
{!Account.Name} {!CloseDate} {!Amount} {!RecordType.Name} - TEMP_NAME: Constant value "Temp Value" used as placeholder during name generation
Error handling#
Name processing protection#
- Uses fault connectors for name parsing failures
- Falls back to "Temp Value" when name generation fails
- Maintains processing continuity despite naming errors
- Handles both standard and Person Account naming scenarios
Amount field management#
- Tracks temporary amount assignment with
TempSetAmountboolean flag - Ensures proper cleanup of temporary fields using field collection
- 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#
movedata__ClearFieldFlowComponent(Apex action)movedata__WriteObjectToLogComponent(Apex action)movedata__NamePatternParserComponent(Apex action)