Custom Setting and Custom Metadata Type are used to store application secrets. We can use both of them to store the application’s configuration data. Although both are used to store configuration data but both have different use cases.
Similarity of Custom Metadata Types and Custom Setting
- Both Custom Setting and Metadata type avoid Governor Limits. If we use SOQL to get custom settings then the Governer limit will be enforced. If we will use the custom setting method to query then it will bypass the governer limit
- Both can be used to store encrypted data.
- Both are internally cached so it will help us in better-performing applications.
- Both can be used in the formula field.
- We can not create tabs for both
Difference between Custom Metadata Types and Custom Setting
|Sr#||Custom Setting||Custom Metadata Type|
|1.||Only metadata of Custom Setting is deployable. We have to create a configuration record post-deployment.||Custom Metadata Types are deployable. We can deploy all configuration records to any org. These are also created using Org refresh.|
|2.||Custom Setting support hierarchy so that we can create different data based on user and profile||Custom metadata types do not support data for profile/user/permission sets directly but we can control visibility using Enhanced Profile User Interface|
|3.||Custom setting records’ values can be edited in code||Custom metadata cannot be edited in code. Custom Metadata is metadata, not a record. so we can only deploy metadata or change using setup.|
It supports record modification only in Manage Package and within the same namespace.
|4.||It is not supporting lookup relationships with another custom setting||Can be set lookup relation with another custom metadata.|
|5.||Cannot use validation rule and page layout.||Can be set validation rule and page layout.|
|6.||Supporting few basic data types and not supporting picklist, text area, or lookup fields||We can create picklist fields in, a long text area and we can also add validation rules to it.|
Where Custom Metadata Types should be used
- Custom Metadata types are configurable data objects so we should use them where application configuration is not changing between org.
- We should use it in AppExchange product to add configuration data. We can give functionality to edit records to the app’s consumer as well using its visibility setting.
Where Custom Setting should be used
- It should be used when we have to configure different data for different org like API URLs which will be different for different org etc.
- We should use it when we want to configure different data for a different set of users/profiles.
[…] Custom Setting and Custom Metadata Type […]