Skip to content

Flow Name: On Membership: Before Update

Last Updated: 2025-10-22 Source Code: https://github.com/AANP-IT/I2C.Salesforce.Metadata/blob/STAGING/force-app/main/default/flows/On_Membership_Before_Update.flow-meta.xml

API Name: On_Membership_Before_Update Status: Active Type: Custom Trigger: Before Membership record is created or updated (when Account is populated and Status is not Expired)

Business Purpose

This flow performs real-time calculation and population of critical membership fields during record creation and updates. It automatically determines member type, membership category, and status based on product information and date logic, ensuring consistent data across membership records.

Process Flow

  1. Trigger Evaluation: Flow activates before saving membership records that have an associated account and are not expired
  2. Calculate Member Type: Determines member type from related product (Fellows are treated specially with blank member type)
  3. Calculate Membership Category: Maps product member type to appropriate category (Individual Members, Company Members, Non-Members, etc.)
  4. Calculate Status: Determines if membership is Active, Within Grace Period, or Expired based on start/end dates and 29-day grace period
  5. Update Fields: Populates Member Type, Membership Category, and Status fields before record is saved
📊 Click to view Process Flow Diagram
flowchart TD
    Start([Start: Membership Create/Update]) --> Check{Account Exists?<br/>Status Not Expired?}

    Check -->|No| End([End])
    Check -->|Yes| CalcType[Calculate Member Type<br/>from Product]

    CalcType --> CalcCategory[Calculate Membership Category<br/>via CASE Statement]
    CalcCategory --> CalcStatus[Calculate Status<br/>Active/Grace Period/Expired]
    CalcStatus --> Update[Update Fields Before Save]
    Update --> End

    style Start fill:#e1f5ff
    style Check fill:#fff4e1
    style CalcType fill:#e1ffe1
    style CalcCategory fill:#e1ffe1
    style CalcStatus fill:#e1ffe1
    style Update fill:#ffe1e1
    style End fill:#e1f5ff

Key Business Rules

  • Member Type Calculation: Fellows get blank member type; all others get type from product
  • Membership Category Mapping: Uses extensive CASE statement to map 16 product member types to 5 categories:
  • "All Individual Members" (Fellows, NP Members, Students, Career Starter, Retired, Associate, Lifetime)
  • "All Company Members" (NP Organization, Corporate Council)
  • "All Individual Non-Members" (Individual Non-Member, Former Member)
  • "All Company Non-Members" (Company Non-Member, Former Company Member)
  • "Corporate Employer Membership" (special category)
  • Status Calculation with 29-Day Grace Period:
  • Active: Start date ≤ today AND end date ≥ today, OR future start date
  • Within Grace Period: End date between (today - 29 days) and today
  • Expired: End date < (today - 29 days)
  • Corporate Council Members: Status is preserved as-is (not auto-calculated)
  • Only processes records with an associated account and not already expired

Dependencies

  • Objects: Membership__c, OrderItem (via Order_Product__c), Product2
  • Fields:
  • Membership__c: Account_Name__c, Member_Type__c, Membership_Category__c, Status__c, Start_Date__c, End_Date__c, Order_Product__c
  • Product2: Member_Type__c
  • Relationships: Membership → OrderItem → Product2

Changes

  • PR-33823: Subscription Expiration when Order is Cancelled
  • PR-31572: Subscriptions as the source of truth
  • PR-28950: Added Fellow Member Type for Membership Record

⚠️ Pre-Go-Live Concerns

CRITICAL - Fix Before Go-Live

  • Hardcoded 29-day grace period: Should be configurable via Custom Metadata or Custom Settings for business flexibility

HIGH - Address Soon After Go-Live

  • Product relationship dependency: Flow will fail if Order_Product__c or Product2 relationship is broken or null
  • Missing error handling: No validation for missing product member type data
  • Complex CASE statement maintenance: 16-option CASE statement is difficult to maintain when member types change

MEDIUM - Future Enhancement

  • Consider moving member type to category mapping to Custom Metadata for easier maintenance
  • Add logging for status changes to provide audit trail
  • Monitor formula performance with large data volumes

LOW - Monitor

  • Formula calculations executed on every create/update may need performance monitoring
  • Corporate Council special handling needs documentation for future maintainers
  • Verify all member type values in production match CASE statement options

Maintenance Notes

  • Complexity: Medium-High - complex formulas with extensive CASE statement and date logic
  • Review Schedule: When new member types are added or grace period policy changes
  • Testing Focus: Test all 16 member type mappings, date edge cases around grace period, and Corporate Council special handling
  • Business Owner: Membership team should maintain member type to category mapping