Flow Name: On Order Summary Update/Fulfilled: Send Order Confirmation Email¶
Last Updated: 2025-10-22 Source Code: On_Order_Update_Fulfilled_Send_Order_Confirmation_Email.flow-meta.xml
API Name: On_Order_Update_Fulfilled_Send_Order_Confirmation_Email Status: Active Type: Custom Trigger: Record-Triggered Flow - After Save on Order
Business Purpose¶
This flow handles automated email receipt generation for fulfilled orders. It intelligently selects appropriate email templates based on account type, product characteristics, and billing contact configuration, then sends personalized order confirmation emails to customers.
Process Flow¶
1. Account and Suppression Validation¶
- Retrieves associated account record
- Checks if Suppress_Invoice_Email__c = true on Order
- If suppression is enabled, updates account's Supress_Invoice_Email__c field and exits
- Validates account exists before continuing
2. Order Item Analysis¶
- Retrieves all OrderItems for the order
- Builds collection of Product2 IDs from order items
- Validates order items exist for processing
3. Email Infrastructure Setup¶
- Retrieves first verified org-wide email address for sender
- Analyzes products to check for downloadable products (IsDownloadableProduct__c = true)
4. Email Template Selection¶
Implements sophisticated template selection based on: - Downloadable Products Priority: If ANY product is downloadable, uses "Invoice_DownloadableProduct" template - Account Type Analysis: Person accounts use "Invoice_Default", business accounts use "Invoice_Company" - Billing Contact Validation: Ensures BillToContactId is populated before sending
5. Email Delivery¶
- Calls EmailService Apex class with selected template ID, order ID, and org-wide email address
- Sends personalized order confirmation to billing contact
📊 Click to view Process Flow Diagram
flowchart TD
Start([Start: Order Updated<br/>Payment Fields Changed]) --> GetAcct[Get Account<br/>Record]
GetAcct --> CheckSuppress{Suppress Invoice<br/>Email?}
CheckSuppress -->|Yes| UpdateAcct[Update Account<br/>Suppression Field]
UpdateAcct --> End([End])
CheckSuppress -->|No| GetItems[Get Order Items<br/>and Products]
GetItems --> CheckItems{Order Items<br/>Exist?}
CheckItems -->|No| End
CheckItems -->|Yes| GetEmail[Get Org-Wide<br/>Email Address]
GetEmail --> CheckDownload{Has Downloadable<br/>Products?}
CheckDownload -->|Yes| UseDownload[Use Invoice_DownloadableProduct<br/>Template]
CheckDownload -->|No| CheckAcctType{Is Person<br/>Account?}
CheckAcctType -->|Yes| UseDefault[Use Invoice_Default<br/>Template]
CheckAcctType -->|No| UseCompany[Use Invoice_Company<br/>Template]
UseDownload --> CheckContact{BillToContactId<br/>Populated?}
UseDefault --> CheckContact
UseCompany --> CheckContact
CheckContact -->|No| End
CheckContact -->|Yes| SendEmail[Call EmailService<br/>Send Receipt]
SendEmail --> End
style Start fill:#e1f5ff
style GetAcct fill:#f0e1ff
style CheckSuppress fill:#fff4e1
style UpdateAcct fill:#ffe1e1
style GetItems fill:#f0e1ff
style CheckItems fill:#fff4e1
style GetEmail fill:#f0e1ff
style CheckDownload fill:#fff4e1
style CheckAcctType fill:#fff4e1
style UseDownload fill:#ffe1e1
style UseDefault fill:#ffe1e1
style UseCompany fill:#ffe1e1
style CheckContact fill:#fff4e1
style SendEmail fill:#ffe1e1
style End fill:#e1f5ff
Key Business Rules¶
- Triggers when payment-related fields change (Balance__c, Payment_Amount__c, Payment_Method__c, Payment_Date__c) AND Payment_Amount__c is not null
- Two-level email suppression: Order-level (Suppress_Invoice_Email__c) and Account-level (Supress_Invoice_Email__c)
- Downloadable product template takes precedence over account type templates
- BillToContactId must be populated to send emails
- Uses EmailService Apex class for email delivery
- Requires verified org-wide email address as sender
Dependencies¶
- EmailTemplate records: Invoice_Default, Invoice_Company, Invoice_DownloadableProduct
- EmailService Apex class for custom email delivery
- OrgWideEmailAddress with verified addresses
- Custom fields: IsDownloadableProduct__c, Suppress_Invoice_Email__c, Supress_Invoice_Email__c
- Payment processing system that populates payment fields
- Order object with BillToContactId field
Changes¶
[PR-32275] Order Receipts implementation with Bill To Contact validation and email template selection logic. [PR-33050] Added suppression field fix to path.
Pre-Go-Live Concerns¶
CRITICAL - Fix Before Go-Live¶
- Standardize email suppression field naming (Suppress vs Supress spelling inconsistency)
- Add validation that selected email templates exist before attempting to send
- Implement fallback template strategy if primary template is missing
HIGH - Address Soon After Go-Live¶
- Add fault handling for email delivery failures
- Implement retry logic for transient email service failures
- Add logging for failed email attempts and template selection decisions
- Validate payment completion status before sending receipts
MEDIUM - Future Enhancement¶
- Make template selection rules configurable via Custom Metadata
- Add support for multiple template types per order based on business rules
- Implement email queue management for high-volume scenarios
- Cache email templates and org-wide email addresses to reduce queries
LOW - Monitor¶
- Track email delivery success rates by template type
- Monitor for orders with payments not receiving receipts
- Alert on email service failures or missing templates
- Dashboard for email volume and performance metrics
Maintenance Notes¶
- Complexity: High - multi-layered template selection logic with external Apex dependency
- Heavy reliance on EmailService Apex class creates single point of failure
- Template selection matrix based on product characteristics and account types
- Note spelling inconsistency in suppression fields (Order vs Account)
- Review quarterly to ensure email templates remain current and accessible
- Test thoroughly when adding new product types or changing account structures