You are here:
Access Rules When Packaging Custom Metadata Types and Records
Understand the access rules when you develop a managed package that contains or reads custom metadata types and records.
Required Editions
| Available in: Salesforce Classic and Lightning Experience |
Protected custom metadata types in managed packages are available in: Developer Edition and scratch orgs Package uploads and installs are available in Group, Enterprise, Performance, Unlimited, and Developer Editions Create, edit, and delete custom metadata type records from installed packages Group and Professional Editions |
When you create a custom metadata type, the package type and the Visibility field determine whether the custom metadata type is public or private. You can only create protected custom metadata types in a developer or scratch org that are then deployed in a managed package.
When a custom metadata type is package-level protected using 2GP, records are only accessible from code within that managed package. Also the subscriber, and other packages, even within the same namespace, can’t access the custom metadata type or its records. A 2GP can only be created through the Salesforce DX command-line interface (SFDX CLI).
To enable package-level protection for a custom metadata type, set the Visibility field to PackageProtected declaratively, or using metadata API.
When a custom metadata type is namespace protected, code that’s in the same namespace as the custom metadata types can read the records. Code that’s in a namespace that doesn’t contain either the type or the protected record can’t read the protected records. To set the accessibility of a package as namespace protected, set the Visibility field to Protected declaratively, or using metadata API.
When a type is public, you can’t convert it to protected. The subscriber can’t create records of a protected type.
If you change a type from protected to public, its protected records remain protected, and all other records become public. If you use Setup to create a record on a protected type, Protected Component is selected by default.
After a managed package is released, subsequent versions of the package can be changed to a less restrictive protection level. For example, a package protected custom metadata type can be re-released as namespace protected. However, you can’t change the protection level to be more restrictive after it has been released in a managed package.
| Entity | Accessibility |
|---|---|
| Package Creator Org |
|
| Metadata API Callout | Metadata API callouts behave as if they’re executed by the subscriber org code. As a result, someone can use a callout to view or change all records created by the subscriber org. However, the callout is used only to view or change the public records of installed managed packages. Configure a remote site setting to the subscriber’s Metadata API endpoint to use the Metadata API in the subscriber’s org. |
| Metadata in Apex | Metadata in Apex callouts behave as if they’re executed by subscriber org code. As a result, someone can use a callout to view or change all records created by the subscriber org. The callout can be used to view or change the public and protected records of installed managed packages. |
| Record Creator |
|
| Subscriber Org | If a field is subscriber controlled, subscribers can also change the value in their own org. If the record is in a managed package, the new field value is propagated only to Subscriber Org new package subscribers. Existing subscribers that upgrade to the latest version of the package don’t get the new field value. |
| SQL Queries in Apex | You can use SOQL queries in your Apex code to view a custom metadata record only if at least one of the following conditions is true.
|

