MayankShrivastavaa/Feature-Flagging-Framework
A lightweight, extensible Feature Flagging Framework for Salesforce that allows controlled rollouts, gradual deployments, and easy management of feature toggles.
Feature Flagging Framework
Deploy Salesforce features according to your pace
A lightweight, extensible Feature Flagging Framework for Salesforce that allows controlled rollouts, gradual deployments, and easy management of feature toggles.
π Key Features
- Simple Facade interface to check if a feature is active
- Pluggable evaluation logic (by role, profile, user, org, etc.)
- In-memory cache to avoid redundant queries
- Test-friendly with easy stubbing/mocking
- Open-Closed design β extend logic without modifying base classes
π How To Use?
1οΈβ£ Create a New Feature Flag Record in Feature_Flag__mdt
2οΈβ£ Call Framework
Feature.isActive(String FeatureName);3οΈβ£ Sit back and observe your feature rolling out according to you β
β οΈ Behavior on Invalid Flags
This framework acts like a black box β it wonβt throw errors to your code.
If something goes wrong internally, it simply returns false.
That means:
- β Invalid Feature Name β
false - β Missing or Misconfigured Rollout Strategy β
false - β Any Internal Exception β
false
All such issues are logged in debug logs, making it easy to trace and fix them during testing.
No exceptions are thrown or leaked β keeping production flow safe and stable.
βοΈ Creating New Feature Flag
π Navigate to:
Setup --> Custom Metadata --> Feature Flag --> Manage Records --> New
| Field | Value |
|---|---|
| Label | Feature Name(Without special characters) |
| Feature Flag Name | Feature_Name(Auto Populated) |
| Rollout Type | Type of rollout for feature |
| Rollout value | Additional value to evaluate status |
π§ Values Map
| βοΈ Rollout Type | π₯ Rollout Value |
|---|---|
| Enabled | Null |
| Disabled | Null |
| Custom Permission | Custom Permission Name |
βWhy This Framework?
Managing feature rollouts in Salesforce often involves custom labels or custom settings, requiring manual updates and cluttering the org with unnecessary entries. This framework provides:
β Scalability β Add new feature types without modifying core logic
β Extensibility β Define custom rollout strategies
β Performance β Cached evaluations for better efficiency
β Maintainability β Follows SOLID principles for clean and structured code
β Devops Friendly β Metadata Driven architecture makes it deployable using metadata api & CI/CD pipelines
π§° Design Patterns Used
| Pattern | Purpose |
|---|---|
| Facade | Expose a clean API to consumers without exposing internal logic using Feature Class |
Feature.isActive(String FeatureName); |
|
| Strategy | Evaluate feature flags using different strategies (e.g. enabled, disabled, custom permissions, etc.) |
| Factory | Dynamically load the right evaluation strategy using FeatureTypeFactory Class |
| Caching | In-memory cache for performance using FeatureFlag Class |
| Separation of Concerns | Keeps evaluation logic, cache, and exposure layers decoupled |
π Current Rollout Strategies
β
Enabled β Global ON
β
Disabled β Global OFF
β
Custom Permission-Based β Checks if a user has a custom permission
β
Profile-Based Rollout β Target specific user profiles
β
Role-Based Rollout β Enable features based on user roles
β
Time-Based Rollout β Toggle features based on start/end date
π§ͺ Planned Rollout Strategies
π Org-Based Rollout β Rollout based on org ID or environment
π % Based Rollout β Gradually enable for a percentage of users
π Formula-Based Rollout β Define rollout logic using formula fields
π Custom Strategy β Plug in your own logic using custom Apex class
π§ Roadmap / Improvements
[ ] Multi feature support - check multiple feature flag using single call
[ ] Admin UI to manage feature rollout - Intrative UI for admin to update rollout stratgies in a single click
[ ] Logging / analytics per flag usage - Track how often and where flags are being evaluated
π€ Contributing
Found a bug or have an idea for improvement? Feel free to raise an issue or open a pull request.
