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, both have different use cases.
Similarity of Custom Metadata Types and Custom Settings
- Both custom settings and metadata types avoid governor limits. If we use SOQL to get custom settings then the Governer limit will be enforced. If we use the custom setting method to query, then it will bypass the governor 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 Settings
| Sr# | Custom Setting | Custom Metadata Type |
|---|---|---|
| 1 | Only metadata of custom settings 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 supports a hierarchy so that we can create different data based on the 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 it using setup. It supports record modification only in the Manage Package and within the same namespace. |
| 4. | It does not support lookup relationships with another custom setting | Can be set to a lookup relation with another custom metadata. |
| 5. | Cannot use the validation rule and page layout. | Can set validation rules and page layouts. |
| 6. | Supporting few basic data types and not supporting picklist, text area, or lookup fields | We can create picklist fields and a long text area and add validation rules to it. |
Where Custom Metadata Types should be used
- Custom metadata types are configurable data objects; therefore, we should use them where application configuration is not changing between Orgs.
- 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.
References:
Related Posts:
- What is SOQL Injection?
- What is PK Chunking?
- What is Data Skew?
- What are Skinny Tables?
- Top 20 Salesforce Data Cloud Interview Questions & Answers for Admins
- Difference Between With Security and Without Security in Apex
- Top 20 Technical Questions for Tech Lead /Salesforce Architect Interview – I
- Interview Questions for Tech Lead /Salesforce Architect Interview – II
- 20 Technical Questions to Test Your Skills in a Tech Lead/Salesforce Architect Interview-3
- Mastering Technical Questions for Tech Lead/Salesforce Architect Interview-4
- Types Of Integration Patterns in Salesforce
4 comments
[…] Custom Setting and Custom Metadata Type […]
[…] out the post-Custom Setting and Custom Metadata Type to understand the both […]
[…] Interview QuestionsSalesforce Apex Interview QuestionTypes Of Integration Patterns in SalesforceDifference Between Custom Setting and Custom Metadata TypeWhat is PK Chunking?What is Data […]
[…] Custom Setting and Custom Metadata Type […]