Custom metadata types can be used for
- Mappings— Make connections between objects, such as a custom metadata type that allocates cities, states, or provinces to specific countries & regions.
- Business rules— Custom functionality can be combined with configuration records. To route payments to the correct destination, use custom information types and Apex code.
- Master data— Assume your organization utilizes a basic accounting system. Create a special metadata type for custom charges such as customs and VAT rates. Subscriber orgs can refer to the master data if this type is included as part of an extension package.
- Whitelists— Keep track of lists like approved contributors and pre-approved vendors.
- Secrets— Protected custom metadata types within a package can be used to store information such as API keys.
Field Manageability
Field manageability is used to manage custom fields when they are created under the Custom Metadata Type. Custom metadata type supports the following custom field types:
- Metadata Relationship
- Checkbox
- Date
- Date and Time
- Number
- Percent
- Phone
- Picklist
- Text
- Text Area
- URL
Access Custom Metadata Type Records
1.Access the Custom Metadata Type records before Spring 21.
2.Access the Custom Metadata Type records after Spring 21.
What about if you don’t need to get all records and need to access only a single record? In that case, you can use the getInstance() method.
Advantages of Custom Metadata:
- It's possible to distribute metadata! There will be no more time-consuming post-deployment configuration, as there will be with custom settings. To create your default custom setting records, you don't need to develop Apex classes.
- Change sets or the force.com migration tool can also be used to deploy custom metadata records with metadata type definitions (ANT). The records in custom settings are uploaded after the definition of the custom setting is deployed.
- ListViews, Page Layouts, and Validation Rules can be created on the Custom Metadata Types.
- Metadata Relationships are a thing of beauty! Lookups between Custom Metadata objects are possible. You may also perform an Object Definition lookup.
- With custom metadata types, you can issue unlimited Salesforce Object Query Language (SOQL) queries for each Apex transaction.
- Custom metadata type is visible in test class without using “SeeAllData”.
- Custom Settings has the same permissions to edit records and configure the system. The “Configure Application” permission allows you to do both. You can edit records with Custom Metadata's "Configure Application," but you'll need "Author Apex" to update the configuration.
Limitations
- Custom metadata records cannot exceed the size of 10MB.
- It does not support formula field data type.
- It cannot be updated through Apex. The only way to edit custom metadata types is by leveraging metadata API.
- 100 custom metadata types can be created per salesforce org.
- We can create only 100 fields per custom metadata type.
- Global picklists are not supported.
Summary
By creating custom metadata, we can create a static set of data and reuse it in our applications, triggers, apex class, test class, Aura components, etc. Click here for more details.