UTIL_FeatureFlag.INT_UserAwareFeatureFlagStrategy
Class · Group: Feature Flags
Learn it: Fast Start - Feature Flags and Feature Flags guide
global interface UTIL_FeatureFlag.INT_UserAwareFeatureFlagStrategy implements UTIL_FeatureFlag.INT_FeatureFlagStrategyImplements: UTIL_FeatureFlag.INT_FeatureFlagStrategy
Extended interface for custom strategies that support user context evaluation. Implement this interface instead of INT_FeatureFlagStrategy when your custom strategy needs to evaluate for a specific user (not just the running user). IMPORTANT: You must implement BOTH methods: isEnabled() for backward compatibility and running user scenarios isEnabledForUser() for explicit user context scenarios The recommended pattern is to have isEnabled() delegate to isEnabledForUser().
Example
public class MY_Region_Strategy implements UTIL_FeatureFlag.INT_UserAwareFeatureFlagStrategy
{
public Boolean isEnabled(FeatureFlag__mdt flag, FeatureFlagStrategy__mdt strategyToEvaluate)
{
return isEnabledForUser(flag, strategyToEvaluate, UserInfo.getUserId());
}
public Boolean isEnabledForUser(FeatureFlag__mdt flag, FeatureFlagStrategy__mdt strategyToEvaluate, Id userId)
{
User targetUser = new SEL_User().findById(userId);
List<String> allowedCountries = strategyToEvaluate.Target__c.split(',');
return allowedCountries.contains(targetUser.Country);
}
}Methods
| Method | Description |
|---|---|
| global abstract Boolean isEnabledForUser(FeatureFlag__mdt flag, FeatureFlagStrategy__mdt strategyToEvaluate, Id userId) | The framework calls this only when it checks a flag for a user who is not the running user, through UTIL_FeatureFlag.isEnabled with a user Id or a username. |
isEnabledForUser
global abstract Boolean isEnabledForUser(FeatureFlag__mdt flag, FeatureFlagStrategy__mdt strategyToEvaluate, Id userId)The framework calls this only when it checks a flag for a user who is not the running user, through UTIL_FeatureFlag.isEnabled with a user Id or a username. For the running user it calls isEnabled instead. Read the user's details from userId, never from UserInfo.
Parameters
| Parameter | Type | Description |
|---|---|---|
flag | FeatureFlag__mdt | The parent Feature Flag custom metadata record |
strategyToEvaluate | FeatureFlagStrategy__mdt | The specific strategy record being evaluated |
userId | Id | The user to evaluate the strategy for (may differ from running user) |
Returns Boolean — true if the feature is enabled for the specified user by this strategy