Class Name: SubscriptionSelector¶
Last Updated: 2025-10-22 Source Code: SubscriptionSelector.cls
API Name: SubscriptionSelector Type: Selector Test Coverage: Not specified
Business Purpose¶
This selector class provides a centralized method for retrieving active subscription data for AANP members, including related order details, product information, and payment scheduling. It supports member portal functionality, subscription management, and billing processes by providing comprehensive subscription data in a single query operation.
Class Overview¶
Scope and Sharing¶
- Sharing Model: with sharing
- Access Modifier: public
- Interfaces Implemented: None
Key Responsibilities¶
- Retrieve active subscriptions for a specific account
- Include related order and product information in a single query
- Provide payment scheduling data from Chargent integration
- Filter subscriptions by active status and auto-renewal flag
- Return empty results for invalid input (null safety)
Public Methods¶
getActiveSubscriptions¶
Purpose: Retrieves all active, auto-renewing subscriptions for a given account with comprehensive related data.
Parameters:
- accountId (String): Salesforce ID of the Account to retrieve subscriptions for
Returns:
- List<Subscription__c>: List of active subscriptions with populated relationships; empty list if accountId is blank
Usage Example:
String accountId = '001xx000000001';
List<Subscription__c> activeSubscriptions = SubscriptionSelector.getActiveSubscriptions(accountId);
for (Subscription__c sub : activeSubscriptions) {
System.debug('Product: ' + sub.Product__r.Name);
System.debug('Next Payment: ' + sub.Chargent_Order__r.ChargentOrders__Next_Scheduled_Payment__c);
}
Business Logic: - Returns empty list if accountId is blank (null safety) - Filters by Account__c = accountId - Filters by Status__c = SubscriptionService.ACTIVE_STATUS - Filters by Auto_Renew__c = TRUE - No LIMIT clause - returns all matching records - No explicit ORDER BY - results may vary
Returned Fields: - Subscription fields: Id, Start_Date__c, End_Date__c, Renew_On__c, CurrencyIsoCode, Product__c, Chargent_Order__c, Order_Product__c - Order fields: Line_Product_Name__c, TotalAdjustedProductAmount - Order Product fields: TotalPrice, Chargent_Recurring_Order__c - Product fields: Name, Family - Chargent Order fields: Next_Scheduled_Payment__c
Private/Helper Methods¶
This class contains no private methods.
Dependencies¶
Apex Classes¶
SubscriptionService: Provides ACTIVE_STATUS constant
Salesforce Objects¶
Subscription__c: Custom subscription object (queried)Order: Related through Order__r relationshipOrderItem: Related through Order_Product__r relationshipProduct2: Related through Product__r relationshipChargentOrders__ChargentOrder__c: Related through Chargent_Order__r relationshipAccount: Parent object (filter criteria)
Custom Settings/Metadata¶
- None directly (SubscriptionService may use settings)
External Services¶
- Chargent Orders package for payment scheduling
Design Patterns¶
- Repository Pattern: Encapsulates data access logic for Subscription__c
- Selector Pattern: Centralized query logic with consistent field selection
- Single Responsibility: Focused on subscription data retrieval only
Governor Limits Considerations¶
SOQL Queries: 1 query per method call DML Operations: None CPU Time: Low - single SOQL query Heap Size: Potentially high if account has many subscriptions (no LIMIT clause)
Bulkification: Not applicable - designed for single account queries Async Processing: Not required
Concerns: - No LIMIT clause could cause heap size issues for accounts with hundreds of subscriptions - Relationship queries increase query complexity and heap usage
Error Handling¶
Strategy: Defensive programming - returns empty list for invalid input Logging: None User Notifications: None
Missing: - No try-catch for SOQL exceptions - No validation of accountId format - No null check after query execution (though Salesforce always returns a list)
Security Considerations¶
Sharing Rules: Enforces sharing (with sharing) - respects OWD and sharing rules Field-Level Security: Not enforced - uses direct SOQL without WITH SECURITY_ENFORCED CRUD Permissions: Not enforced - assumes caller has read access Input Validation: Checks for blank accountId but not format or existence
Test Class¶
Test Class: Not specified (likely has associated test class) Coverage: Not specified Test Scenarios Needed: - Account with active subscriptions - Account with no subscriptions - Null/blank accountId handling - Inactive subscriptions (should not be returned) - Non-auto-renewing subscriptions (should not be returned) - Multi-currency subscriptions - Large number of subscriptions (heap size testing)
Changes & History¶
- No documented change history available
Pre-Go-Live Concerns¶
CRITICAL - Fix Before Go-Live¶
- NO LIMIT CLAUSE: Query lacks LIMIT which could cause heap size issues for accounts with many subscriptions
- NO ERROR HANDLING: Missing try-catch for SOQL exceptions
- FLS NOT ENFORCED: No WITH SECURITY_ENFORCED clause
HIGH - Address Soon After Go-Live¶
- Add LIMIT clause (e.g., LIMIT 200) appropriate for expected subscription volumes
- Add try-catch with proper error handling and logging
- Add validation for accountId format (15 or 18 char Id)
- Consider adding ORDER BY clause for consistent results
- Add logging for query execution and performance monitoring
MEDIUM - Future Enhancement¶
- Add optional parameter for subscription status (not just active)
- Implement result caching for frequently queried accounts
- Add support for date range filtering (subscriptions active during period)
- Add pagination support if accounts can have many subscriptions
- Consider making field selection configurable
- Add method overload to return only specific fields when full data not needed
LOW - Monitor¶
- Monitor query performance and execution time in production
- Track heap size usage for accounts with many subscriptions
- Review field selection - ensure all queried fields are actually used
- Monitor usage patterns to identify optimization opportunities
Maintenance Notes¶
Complexity: Low-Medium Recommended Review Schedule: Quarterly Key Maintainer Notes: - This selector is likely used in member-facing portals - performance is critical - The lack of LIMIT clause is a significant risk if subscription volumes grow - All relationship queries (Order__r, Product__r, etc.) add to query complexity - The Auto_Renew__c = TRUE filter suggests non-auto-renewing subscriptions exist but are intentionally excluded - SubscriptionService.ACTIVE_STATUS constant must remain consistent across environments - When modifying field selection, coordinate with all consuming code - Consider creating separate methods for different use cases (e.g., portal display vs. batch processing) - If Chargent package is upgraded, verify ChargentOrders__Next_Scheduled_Payment__c field still exists - Multi-currency orgs: CurrencyIsoCode field is critical for proper amount display