How to deploy a custom metadata type from sandbox to another sandbox or production org using change sets?
The normal practice is you create an outbound change set (CS), add the custom metadata type and the fields to the change set and deploy. Right? Well, that’s not it! If you just add the object (custom metadata type) and the fields to the outbound and deploy, it won’t deploy the data/records in the custom metadata type. It only deploys the fields without data!
Custom metadata types are superior to the custom settings in this aspect that we have the power to deploy the data/records also using change sets. So, you don’t need to manually copy/data load the data from sandbox to other sandboxes or production. You can just deploy the data as well. In this post, I will show you how!
Example: I have a custom metadata type called “Constants” with a field called “Value” in one of my sandboxes. Here, I store all the system constants like API Keys etc.
Here’s the data stored in the Constants custom metadata.
1. Add the ‘Custom Metadata Type’ component to the change set. Note the component type is Custom Metadata Type in the drop-down and select the ‘Constants’. Here you are adding the object.
2. Add the custom field. Now add the field called Value from constants object
3. Here’s the additional step. Add the data. Select the custom metadata type called ‘Constants’ from the Component Type. There you see, all your custom metadata types are available as component types in the drop-down directly! Select the fields from this, whose values need to be deployed. That’s it!
Note: Observe the difference in Step 1 and Step 3. In Step 1, you are adding the object (metadata). In Step 3, you are adding the records (data) to the change set. Once you deploy this change set, you will now see the metadata and data/records in your destination org.
- Add the object [Component Type: Custom Metadata Type]
- Add the fields [Component Type: Custom Fields]
- Add the data [Component Type: Actual “custom metadata type” Name]