Metadata Access in Apex Code
Your package may need to retrieve or modify metadata during installation or update. The Metadata namespace in Apex provides classes that represent metadata types, as well as classes that let you retrieve and deploy metadata components to the subscriber org. These considerations apply to metadata in Apex:
- You can create, retrieve, and update metadata components in Apex code, but you can’t delete components.
- You can currently access records of custom metadata types and page layouts in Apex.
- Managed packages not approved by Salesforce can’t access metadata in the subscriber org, unless the subscriber org enables the Allow metadata deploy by Apex from non-certified Apex package version org preference. Use this org preference when doing test or beta releases of your managed packages.
If your package accesses metadata during installation or update, or contains a custom setup interface that accesses metadata, you must notify the user. For installs that access metadata, notify the user in the description of your package. The notice should let customers know that your package has the ability to modify the subscriber org’s metadata.
You can write your own notice, or use this sample:
This package can access and change metadata outside its namespace in the Salesforce org where it’s installed.
Salesforce verifies the notice during the security review.
For more information, see Metadata in the Apex Developer Guide.