In Salesforce, metadata is one of the most critical components or functionalities. In fact, most of the magic is impossible to achieve without Metadata! Yet, many Salesforce administrators are still unable to grasp the fundamental nature of Metadata. Hence, they fail to get the most out of it.
This blog aims to help you learn everything about Custom Metadata Types in Salesforce. Let’s look at what Metadata Salesforce is and how salesforce experts create custom metadata types in Salesforce.
What is Salesforce Metadata?
Metadata is data that describes other data. It refers to the fields, configurations, code, logic, and page layouts that create your Salesforce environment’s information architecture and look & feel. Metadata can be imported into Salesforce, changed using the product interface, or altered with the Salesforce Metadata API.
Let’s use an example to grasp the concept – There is an object named Account in a Salesforce org. You add metadata and data to an account when you add records with a customer’s contact information. Metadata includes field names like first and last names. The values in those fields, such as Tom and Willy, constitute data.
What Is A Custom Metadata Type?
There are several types of Metadata. Each one represents a different way a business function can be customizable. A custom metadata type is a custom object that defines the metadata structure for an application.
Only metadata makes up the fields of custom metadata types and the values in the fields. Custom metadata type records are also metadata, not data. It’s a very useful tool because metadata can be imported into Salesforce, changed in the interface, and processed using the Metadata API.
Rather than storing hard-coded data, custom metadata types allow you to configure applications by creating reusable functionality that decides behavior depending on metadata. And declarative tools can help you with a lot of this customizing.
In short, With Custom Metadata Types, Salesforce administrators can customize, deploy, package, and upgrade application metadata that you design yourself. Moreover, you need not transfer custom metadata type records manually. Instead, you can deploy them from a sandbox using change sets or packed in managed packages.
Here are a few broad categories for Custom Metadata types:
Category | Feature | Examples |
Data | Core components within the data structure on which majority customisation is done. | Custom Applications, Value Sets, and Custom Objects |
Programmability | Custom code is created on the top of the platform. | Apex Classes, Apex Page, and Apex Triggers. |
Presentation | Customization on how different users interact with the platform. | Components, VisualForce and Lightning pages. |
Salesforce Metadata Types: Features and Benefits
- Because Force.com is based on a metadata-driven architecture, it supports multi-tenant applications.
- Everything in Salesforce.com is open to Salesforce metadata developers, and application users are represented internally as metadata.
- Because metadata is an essential component of Force.com apps, the platform’s runtime engine must optimize metadata access.
- The technology would not scale due to frequent metadata access; hence Salesforce metadata would be used instead.
- Force.com employs metadata caches to keep the most recently used metadata in memory.
- Metadata eliminates time-consuming disc I/O and recompilation of code.
- Application Metadata reduces the time it takes for an app to respond.
Custom Metadata Vs. Custom Setting – Types of Salesforce
Custom metadata types can perform the same functions as list custom settings. In fact, in an even better way. Below is a high-level comparison of the similarities and differences between a custom setting and a custom metadata type.
Functionality | List Custom Setting | Custom Metadata Type |
Metadata retrieve/deploy and package install definitions | Available | Available |
Metadata retrieve/deploy and package install records | Not Available | Available |
Unlimited calls/queries | Available | Available |
Native user interface | Available | Available |
Protect (hide) the object | Available | Available |
Protect (hide) individual records | Not Available | Available |
Control over editability of fields | Not Available | Available |
Setup audit trail history | Not Available | Available |
Apex tests see records without seeing “SeeAllData” annotation | Not Available | Available |
Native Apex support to update and create records | Available | Not Available |
How To Create Custom Metadata Types?
To begin with, create a custom Metadata type and add two custom fields: a Minimum Spending field and a Default Discount field. The minimum spending defines how much a specific account needs to spend to qualify for a support tier. A default discount is a discount that is automatically assigned to a given level.
Add a custom metadata type record once you create custom fields with the help of top IT consulting company. You can store master data in custom metadata records. In our example, you’ll make a record for each support tier that applies to your organization.
Create Custom Metadata Types
- Go to – Setup. Enter Custom Metadata Types in the Quick Find box and select Custom Metadata Types.
- Click New Custom Metadata Type.
- Enter ‘Support Tier’ for Label. Enter ‘Support Tiers’ for Plural Labels.
- Click ‘Save’.
- Next, you land on the Custom Metadata Type Support Tier page. The Custom Metadata Support page holds details on the custom metadata type. You may create validation rules, add custom fields, and alter page layouts from here.
Create Custom Fields
We want each support tier to be associated with a minimum spending amount using our custom metadata type. Additionally, we also want to incorporate a default discount. Let us start by adding two custom fields in Salesforce. Including a custom field to a custom metadata type works the same for standard or custom objects.
- Click New in the Custom Fields section of the Support Tier page.
- Select Percent. Then click Next.
- Type Default Discount for Field Label.
- Type 2 for length.
- Click Next. Then click Save.
- Create another custom field. This time use Number as the field type.
- Type Minimum Spending for the Field Label.
- Type 6 For Length.
- For Field Manageability, select Any user with the Customize Application permission.
- Click Next. Then click Save.
Conclusion
Salesforce Custom metadata types are often preferable to custom settings, but choosing which one to employ requires caution. Custom metadata types are the best option if a user edit or data upload only changes the settings. If, on the other hand, the settings change regularly as a result of a transaction, custom settings may be preferable.