In this post, we will talk about the difference between custom settings and custom metadata Types in Salesforce. Before to that let understand what is custom settings and Custom Metadata Type in Salesforce.
What is Custom Setting?
Custom Settings are like custom objects. They are generally used to create custom sets of data and can be associated with an organization, profile or a specific user. The visibility of the custom setting can be controlled by marking it as public or protected. Custom Settings data set can be used in Formula fields, Validation rules, flows, Apex and SOAP API.
What is Custom Metadata Types?
The term “Metadata” is nothing but data about data. In simple words, when you are creating a record within Salesforce, you are creating data as well as metadata. The data which you are trying to enter, is captured or stored in the fields which are nothing but columns of your Object.
Custom Metadata Types in Salesforce are similar to custom objects. It has a suffix of “__mdt” instead of “__c” in the API namespace.
Differences between Custom Metadata Types and Custom Settings
We know the primary difference between custom metadata type and custom setting is that custom metadata type records are deployable but we can not deploy custom setting data. But there are lots of other difference. Let have a look.
|Custom Settings||Custom Metadata Types|
|Type||Custom Settings are also similar to custom objects. You can either create a List based or hierarchy based custom setting.||Custom metadata does not support Hierarchy type of data based on user profile or a specific user.|
|Deployment||Custom settings data cannot be deployed using packages or Metadata API/Change Sets.||Custom metadata types data can be easily packaged and deployed. Metadata types can also be deployed via Change Sets/Metadata API.|
|Relationship Field||Custom settings do not support relationship fields.||You can create lookups between Custom Metadata objects.|
|Suffix||It has a suffix of “__C” like custom object||It has a suffix of “__mdt”|
|Test Class||Custom setting data is not visible in test classes.||Custom metadata types are visible in test class without the “SeeAllData” annotation.|
|DML in Apex||You can perform CUD (Create, Update, Delete) operation on custom setting in apex.||You cannot perform CUD (Create, Update, Delete) operation on custom metadata type in apex.|
|SOQL||You can access custom setting data using instance methods and can avoid SOQL queries to database||With custom metadata types, you can issue unlimited (SOQL) queries for each Apex transaction. But method is also available.|
We recommend use custom setting for hierarchy based data and use Custom Metadata Types for list base data.