Skip to content

Flow Name: On Subscription: Calculate Status Before Update

Last Updated: 2025-08-08 Source Code: On_Subscription_Calculate_Status_Before_Update.flow-meta.xml

API Name: On_Subscription_Calculate_Status_Before_Update Status: Active Type: Custom Trigger: Before Subscription record is created or updated

Business Purpose

Automatically calculates and maintains subscription status (Active/Expired) based on start and end dates, and sets renewal and grace period dates. Makes Subscriptions the source of truth for membership status. Referenced PRs: 31572, 33333, 32284.

Process Flow

  1. Triggers before Subscription create/update when:
  2. Start_Date__c changes OR
  3. End_Date__c changes OR
  4. Grace_Period__c is less than current date

  5. Retrieve Grace Period:

  6. Looks up Grace_Period value from Environment_Settings__mdt
  7. Defaults to 30 days if metadata not found

  8. Calculate Fields:

  9. Status: Active if (Start Date <= Today AND End Date >= Today), else Expired
  10. Renew_On__c: End Date + 1 day
  11. Grace_Period__c: End Date + Grace Period days (from Product or default 30)

  12. Updates all three fields in single operation

📊 Click to view Process Flow Diagram
flowchart TD
    Start([Start: Subscription Create/Update<br/>Before Save Trigger]) --> Decision{Check Matching<br/>Scenario}

    Decision -->|Scenario 1:<br/>Start Date or End Date Changed| GetGrace[Get Grace Period<br/>from Environment_Settings__mdt]
    Decision -->|Scenario 2:<br/>Grace Period < Today| GetGrace
    Decision -->|No Match| End([End])

    GetGrace --> Formulas[Calculate Formulas:<br/>• DayAfterEndDate = End Date + 1<br/>• GracePeriodDate = End Date + Grace Days<br/>• Status = Active or Expired]

    Formulas --> Update[Update Subscription Fields:<br/>• Status__c<br/>• Renew_On__c<br/>• Grace_Period__c]

    Update --> End

    style Start fill:#e1f5ff
    style Decision fill:#fff4e1
    style GetGrace fill:#f0e1ff
    style Formulas fill:#e1ffe1
    style Update fill:#ffe1e1
    style End fill:#e1f5ff

Key Business Rules

  • Status calculation: IF(Start <= TODAY() && End >= TODAY(), 'Active', 'Expired')
  • Grace Period prioritizes Product__r.GracePeriod__c, falls back to metadata setting
  • Renew On date is always End Date + 1 day
  • Processes on both create and update
  • Operates in Before Save context for optimal performance
  • Scenario 1: Start or End date changes
  • Scenario 2: Grace Period date passes

Dependencies

  • Objects: Subscription__c (custom)
  • Fields:
  • Start_Date__c, End_Date__c, Status__c
  • Renew_On__c, Grace_Period__c
  • Product__r.GracePeriod__c
  • Custom Metadata: Environment_Settings__mdt (Grace_Period record)
  • Default Values: GracePeriodValue = 30 days

Changes

  • PR-31572: Subscriptions as the source of truth
  • PR-33333: Reflect End Date changes
  • PR-32284: Retrieve and use Grace Period Value from Environment_Settings__mdt

⚠️ Pre-Go-Live Concerns

CRITICAL - Fix Before Go-Live

  • Status Overwrite: User-set status values will be overwritten by formula - may not be desired
  • Missing Validation: No validation that Start Date is before End Date
  • Timezone Issues: Uses TODAY() which is org timezone - subscriptions might expire at wrong time for users in different timezones

HIGH - Address Soon After Go-Live

  • Grace Period Logic: Uses ISBLANK but should also check for zero or negative values
  • No User Notification: Users don't receive alerts when subscriptions expire
  • Bulk Updates: Large date changes could trigger governor limits

MEDIUM - Future Enhancement

  • Configurable Status: Allow manual status override for special cases
  • Date Validation: Add validation to ensure Start Date < End Date
  • Audit Trail: Enable field history tracking for Status field

LOW - Monitor

  • Grace Period Accuracy: Verify grace period calculations match business expectations
  • Performance: Before-save trigger - should be fast but monitor with bulk operations
  • Edge Cases: Monitor subscriptions that span daylight saving time changes

Maintenance Notes

Complexity: Low-Medium - Formula-based with metadata lookup Review Schedule: Review quarterly when grace period policies change Critical Business Logic: Core calculation for subscription lifecycle - changes affect member access PR Impact: Three separate PRs indicate evolving requirements - expect future changes Source of Truth: Flow description indicates Subscriptions are "source of truth" - other flows may depend on this