GitHunt
MA

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

Feature Flag Record

🧭 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.

MayankShrivastavaa/Feature-Flagging-Framework | GitHunt