Friday, September 30, 2016

Custom Settings VS Custom Metadata

What are custom metadata?
Before we get into custom metadata, lets first try to understand what is metadata? Metadata is simplest terms can be defined as data about your data. In other words its the information about your data. For eg: If you add a field on your account object. You would need to know its type (text, number, picklist etc), whether its required or optional, is there any default value etc. All this definition about your data is called metadata.

Custom metadata takes this concept and extends it by allowing developers to define there own metadata. 

OK, but where is it used?
Custom metadata types are ideal for any records that represent metadata for your app. In other words any records that represents configuration or controls the behavior of your app can be considered for custom metadata. For eg: You want to integrate your application with a number of endpoint. Typically you would create custom objects or custom settings to store the information about the API's. Each record would represent an actual integration. 
The problem with using custom object or custom settings for storing this information is that you can only deploy the definition of custom object or custom settings into another org. The records needs to be transferred separately in some other way. 
Solution: Metadata to rescue. Since the records of custom metadata are treated as metadata they can be deployed from one sandbox to another using change set or managed packages.

Will custom metadata replace custom settings?
In most of the cases Yes, custom metadata type can replace custom settings however there are use cases where you might want to use custom settings. Please see the below decision tree and comparison chart that could help you in deciding what to use.

Decision Tree



Comparison Chart

How to use custom metadata?

Creating custom metadata is very similar to creation of custom object or custom settings.
Step 1: Go to Setup and search for "Custom Metadata Types"

Step 2: Click on "New Custom Metadata Type"

Step 3: Save Custom Metadata Type

Step 4: Click on "New" in custom field section


Step 5: Create the required fields

Step 6: Click on "Manage UI Settings"

Step 7: Click on New and Create Records

Step 8: Query in Apex
 List<UI_Settings__mdt> fieldInfoList = [SELECT Id, DeveloperName, Country_Applicable__c, Help_Text_Reference__c, Object_Name__c, Required__c, Screen_Name__c, Screen_Sequence__c, Field_API_Name__c FROM UI_Settings__mdt];  



2 comments:

  1. I am surprised there is no mention of hierarchical custom settings - they behave differently, and it seems if you need different values based on Org, Profile or User, that's a reason for sticking with custom settings - should be in your flowchart.

    ReplyDelete
  2. Valid point. Made the required changes.

    ReplyDelete