Winter 18 introduced the FeatureManagement Apex Class, which contained a method which I was not expecting: changeProtection. According to the docs, changeProtection can be used to "Unprotect" objects or custom permissions which were previously released as protected. However, it is not clear from the documentation whether this method is supposed to be usable to "Protect" unprotected objects, or whether it is possible to use this with ANY Custom Object type, i.e. with something other than Custom Settings or Custom Metadata Types.

When I create a brand-new regular Custom Object, and then try to mark it "Protected" like this:

System.FeatureManagement.changeProtection('MyCustomObject__c','CustomObject', 'Protected');

I get the following error:

System.TypeException: Once protection has been removed from CustomObject, never may it be restored.

Which doesn't make any sense in my case, as I've just created a brand-new Custom Object and am trying to mark it as Protected before I release it.

I'm probably trying to use this method in a way it was not designed, but I'd love to get some confirmation on that.

However, the docs seem to indicate that this is a possible use of this feature:

Be sure to protect any custom objects that you want to hide before you release the first package version that contains them.

Which is exactly what I'd like to do! If we can make regular Custom Objects Protected --- that would be a HUGE HUGE Winter 18 feature.

  • Are you working with a managed package? 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. – Adrian Larson Nov 30 '17 at 16:03
  • @AdrianLarson Yes, i am working with a managed package --- all of the methods in the FeatureManagement class have no meaning / use outside of the managed package ecosystem. – zachelrath Nov 30 '17 at 18:03

After some guidance by Salesforce, I figured it out:

Winter 18 introduced the ability to "Protect" regular Custom Objects, in addition to the preexisting ability to Protect Custom Settings and Custom Metadata Types included in a Managed Package. When a Custom Object is protected, much like with Custom Settings / Custom Metadata Types, that object will only be accessible to Apex Code running within the Managed Package. Other Apex Code / SOQL queries / the API will not have access to that Custom Object.

The key piece that I was missing was that this capability is only available via the "New Custom Object" wizard --- you cannot (yet) do this via Schema Builder.

You also must log a case with Partner Support to have the "Feature Management" capability enabled for your Managed Package Development Org and Partner Business Org.

If you have this feature enabled, then you will see a new "Visibility" section when creating a new Custom Object via the wizard:

Custom Object Visibility

This is how you add protection to a newly-created Custom Object.

The System.FeatureManagement.changeProtection method is then mainly useful to de-protect a previously-released, protected custom object. Understandably, though, once an object has been de-protected and released, it cannot be re-protected.

So in summary, the changeProtection method's purpose for Custom Objects is principally to de-protect an already protected Custom Object --- to protect a net-new Custom Object, use the declarative options available during the "New Custom Object" wizard.

  • does this mean you can't change the visibility of a Custom Object that's already packaged? I'd like to change the visibility of a custom object to 'Protected' since I'll be using FMA to control it later. – d_k Aug 28 '19 at 4:55
  • Can you also make certain fields protected? – d_k Aug 28 '19 at 13:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.