FeatureManagement Class
Use the methods in the System.FeatureManagement class to check and modify the values of feature parameters, and to show or hide custom objects and custom permissions in your subscribers’ orgs.
For information about feature parameters, see Manage Features in Second Generation Managed Packages in the Second-Generation Managed Packaging Developer Guide, or Manage Features in First-Generation Managed Packages in the First-Generation Managed Packaging Developer Guide.
The set methods (setPackageBooleanValue, setPackageDateValue, setPackageIntegerValue) use DML operations on setup sObjects. To learn more about mixing operations in a test, see Mixed DML Operations in Test Methods.
The following are methods for FeatureManagement.
-
changeProtection(apiName, typeApiName, protection)
Hides or reveals custom permissions, or reveals custom objects, in your subscriber’s org.
-
checkPackageBooleanValue(apiName)
Checks the
value__cvalue of theFeatureParameterBoolean__crecord for a feature parameter in your subscriber’s org. You set the record’s value usingsetPackageBooleanValue(apiName, value). -
checkPackageDateValue(apiName)
Checks the
value__cvalue of theFeatureParameterDate__crecord for a feature parameter in your subscriber’s org. You can set the record’s value usingsetPackageDateValue(apiName, value). -
checkPackageIntegerValue(apiName)
Checks the
value__cvalue of theFeatureParameterInteger__crecord for a feature parameter in your subscriber’s org. You can set the record’s value usingsetPackageIntegerValue(apiName, value). -
Checks whether a custom permission is enabled.
-
setPackageBooleanValue(apiName, value)
Sets the
value__cvalue of theFeatureParameterBoolean__crecord for a subscriber-to-LMO feature parameter in your subscriber’s org. You can check the record’s value usingcheckPackageBooleanValue(apiName). -
setPackageDateValue(apiName, value)
Sets the
value__cvalue of theFeatureParameterDate__crecord for a subscriber-to-LMO feature parameter in your subscriber’s org. You can check the record’s value usingcheckPackageDateValue(apiName). -
setPackageIntegerValue(apiName, value)
Sets the
value__cvalue of theFeatureParameterInteger__crecord for a subscriber-to-LMO feature parameter in your subscriber’s org. You can check the record’s value usingcheckPackageIntegerValue(apiName).
Hides or reveals custom permissions, or reveals custom objects, in your subscriber’s org.
public static void changeProtection(String apiName, String typeApiName, String protection)
-
apiName: Type: String The API name of the custom object or custom permission to show or hide—for example,
'MyCustomObject__c'or'MyCustomPermission'. -
typeApiName: Type: String The API name of the type that you want to show or hide:
'CustomObject'or'CustomPermission'. -
protection: Type: String
To show a custom object or custom permission,
'Unprotected'.To hide a custom permission,
'Protected'.
Type: void
For custom permissions, you can toggle the protected value indefinitely. However, after you’ve released unprotected objects to subscribers, you can’t set visibility to Protected. Be sure to protect any custom objects that you want to hide before you release the first package version that contains them.
To hide custom permissions in released packages:
To unhide custom permissions and custom objects in released packages:
Checks the value__c value of the FeatureParameterBoolean__c record for a feature parameter in your subscriber’s org. You set the record’s value using setPackageBooleanValue(apiName, value).
public static Boolean checkPackageBooleanValue(String apiName)
- apiName: Type: String The
fullName__cvalue of the feature parameter whose value you want to check—for example,'SpecialAccessAvailable'.
Type: Boolean
The value that’s currently assigned to the value__c field on the FeatureParameterBoolean__c record that associates the feature parameter with its related license.
Checks the value__c value of the FeatureParameterDate__c record for a feature parameter in your subscriber’s org. You can set the record’s value using setPackageDateValue(apiName, value).
public static Date checkPackageDateValue(String apiName)
- apiName: Type: String The
fullName__cvalue of the feature parameter whose value you want to check—for example,'TrialExpirationDate'.
Type: Date
The value that’s currently assigned to the value__c field on the FeatureParameterDate__c record that associates the feature parameter with its related license.
Checks the value__c value of the FeatureParameterInteger__c record for a feature parameter in your subscriber’s org. You can set the record’s value using setPackageIntegerValue(apiName, value).
public static Integer checkPackageIntegerValue(String apiName)
- apiName: Type: String The
fullName__cvalue of the feature parameter whose value you want to check—for example,'NumberOfLicenses'.
Type: Integer
The value that’s currently assigned to the value__c field on the FeatureParameterInteger__c record that associates the feature parameter with its related license.
Checks whether a custom permission is enabled.
public static Boolean checkPermission(String apiName)
- apiName: Type: String The API name of the custom permission to check the value of—for example,
'MyCustomPermission'.
Type: Boolean
Shows whether the permission is enabled (true) or disabled (false).
Sets the value__c value of the FeatureParameterBoolean__c record for a subscriber-to-LMO feature parameter in your subscriber’s org. You can check the record’s value using checkPackageBooleanValue(apiName).
public static void setPackageBooleanValue(String apiName, Boolean value)
- apiName: Type: String The
fullName__cvalue of the feature parameter whose value you want to set—for example,'SpecialAccessAvailable'. - value: Type: Boolean The value to assign to the
value__cfield on theFeatureParameterBoolean__crecord that associates the feature parameter with its related license.
Type: void
Sets the value__c value of the FeatureParameterDate__c record for a subscriber-to-LMO feature parameter in your subscriber’s org. You can check the record’s value using checkPackageDateValue(apiName).
public static void setPackageDateValue(String apiName, Date value)
- apiName: Type: String The
fullName__cvalue of the feature parameter whose value you want to set—for example,'TrialExpirationDate'. - value: Type: Date The value to assign to the
value__cfield on theFeatureParameterDate__crecord that associates the feature parameter with its related license.
Type: void
Sets the value__c value of the FeatureParameterInteger__c record for a subscriber-to-LMO feature parameter in your subscriber’s org. You can check the record’s value using checkPackageIntegerValue(apiName).
public static void setPackageIntegerValue(String apiName, Integer value)
- apiName: Type: String The
fullName__cvalue of the feature parameter whose value you want to set—for example,'NumberOfLicenses'. - value: Type: Integer The value to assign to the
value__cfield on theFeatureParameterInteger__crecord that associates the feature parameter with its related license.
Type: void