Flow Name: [I2C] Subscription Auto-Renewal Changed¶
Last Updated: 2025-10-09 Source Code: I2C_Subscription_Auto_Renewal_Changed.flow-meta.xml
API Name: I2C_Subscription_Auto_Renewal_Changed Status: Active Type: Custom Trigger: Subscription creation/update (after save) when Auto_Renew__c changes or is set on new records
Business Purpose¶
Manages subscription auto-renewal settings by creating or finding appropriate ChargentOrders for recurring billing, preventing duplicate product subscriptions, and maintaining proper OrderItem relationships for automated payments.
Process Flow¶
- Account Validation: Retrieves Account and validates auto-renewal eligibility
- Auto-Renewal Toggle Decision:
- Disabled Path: Dissociates OrderItem from recurring ChargentOrder and recalculates charges
- Enabled Path: Proceeds to setup recurring billing
- Recurring Order Management:
- Gets existing recurring ChargentOrders (excluding PAC orders)
- Transforms order IDs and retrieves associated OrderItems
- Checks for duplicate products to prevent conflicts
- Date Matching Logic:
- Filters ChargentOrders by payment date (subscription end date + 1)
- Uses complex conditions to match payment start date or next scheduled payment
- Order Creation/Assignment:
- Existing Order: Uses latest matching ChargentOrder by creation date
- New Order: Creates ChargentOrder with hardcoded "Annual" frequency and "Recurring" status
- Finalization: Assigns OrderItem to ChargentOrder and recalculates recurring charges
📊 Click to view Process Flow Diagram
flowchart TD
Start([Start: Subscription creation/update (after save) when Auto_Renew__c changes or is set on new records]) --> 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¶
- Requires both subscription and account to have auto-renewal enabled
- Prevents duplicate products in recurring orders through product ID collection
- Uses end date + 1 day as the scheduled payment date
- Only processes non-PAC recurring orders (ChargentOrders_Recurring_Pac__c = false)
- Creates new orders when no existing order matches the required payment date
Dependencies¶
- Subscription__c with Auto_Renew__c, End_Date__c, Account__c, Product__c, Order__c fields
- Account with Auto_Renew__c and Auto_Renewal_Payment_Method__c fields
- ChargentOrders__ChargentOrder__c with payment scheduling and frequency fields
- OrderItem with Chargent_Recurring_Order__c lookup
- Apex class: I2C_RecalculateRecurringCharge
Changes¶
Flow description indicates this handles auto-renewal details being set/changed on Subscription records.
⚠️ Pre-Go-Live Concerns¶
CRITICAL - Fix Before Go-Live¶
- Hardcoded values that should be configurable: Payment frequency hardcoded as "Annual" and status as "Recurring"
- Missing null checks on required operations: No validation that Account.Auto_Renewal_Payment_Method__c exists before assignment
- Flows that modify critical business data without validation: Creates ChargentOrders and modifies OrderItem relationships without comprehensive validation
HIGH - Address Soon After Go-Live¶
- Missing error handling or fault paths: No error handling for ChargentOrder creation, OrderItem updates, or Apex action failures
- Complex date matching logic could fail with edge cases or timezone issues
- Collection processing assumes data consistency without validation
- Multiple async Apex calls without error handling
MEDIUM - Future Enhancement¶
- Replace hardcoded payment frequency with dynamic logic based on product or subscription settings
- Add comprehensive error handling and rollback mechanisms for failed operations
- Simplify complex date matching logic for better maintainability
- Add validation that all required relationships exist before processing
LOW - Monitor¶
- Monitor Apex action success rates for charge recalculation
- Track duplicate product prevention effectiveness
- Validate date calculation accuracy across different timezones
Maintenance Notes¶
HIGH COMPLEXITY FLOW with intricate business logic for subscription auto-renewal management. Critical for subscription billing functionality. Contains hardcoded values and lacks error handling. Requires comprehensive testing and monitoring. Consider breaking into smaller, focused flows for better maintainability.