
Hello there!
Hope you are safe and doing well.
Are you facing challenges inserting mass CustomMetadataType records in Salesforce org? this blog post will help you. đ
Letâs check what options we have to do this:
Salesforce Data Loader? As of now âData Loaderâ does not support CustomMetaDataType (We donât know yet when this will be available in the future). We know âData Loaderâ is to load the data but here CustomMetadata is not real data.
Ant Migration Tool? You can choose this tool for this job but this is not what I recommend.
The SalesforceDX CLI? Yes, we can now import the CustomMetadataType records using cmdt command. This is a recommended approach for this task.
Letâs see how we can do mass CustomMetadataType records insert using Salesforce CLI.
Salesforce Developer Experience (DX) is a new way to manage and develop the salesforce application. This provides the powerful command-line interface (CLI) that makes things super easy for the developers to work with Salesforce Orgs for developing, continuous integration, and delivery.
Create a CustomMetadataType in your Salesforce org. If you already have (custom metadata type) skip the creation/definition steps.
Setup> Quick find> search ‘custom metadata’ and click on “New Custom Metadata Type”.
Create the Custom Metadata Type and fields.

Open your VS CODE IDE and create a project (If you already have a project created on your vscode skip this step)



Authorize your org:



Now fetch the Custom Metadata Type definition from your Salesforce org to your local machine. Click on the icon Retrieve Source From Org on ‘Custom Object’.
Here I am using the ‘Org Browser’ extension to fetch the metadata information from Salesforce org.

Prepare your .csv file and store in your project folder or any folder you want.
- Put the column name the same as the field API name.
- Label (Name) API Name can only contain underscores and alphanumeric characters. It must be unique, begin with a letter, not include spaces, not end with an underscore, and not contain two consecutive underscores.
- If you have any space or any other special char in the “Name” (Label) field replace it with an underscore(_)

Open the terminal in VS Code

Execute this cmdt command.

e.g ‘sfdx force:cmdt:record:insert –filepath CountryMapping.csv –typename CountryMapping__mdt‘

Now you will see all custom metadata type records that have been created in your local machine in the project folder.

Right-click on the Custom Metadata folder and click on “Deploy Source to Org”

After successful execution of this command, your Custom Metadata Type records will be inserted in your org.

If you donât want to do the above steps, you have easier options as well – You can find a Custom Metadata Loader tool on GitHub that you have to download and install in your Salesforce org. From this tool, you can easily upload your .csv file records in Custom Metadata Type.

Mass Insert Custom Metadata Type Records
Tweet
Reference:
- ANT tool: https://developer.salesforce.com/docs/atlas.en-us.daas.meta/daas/forcemigrationtool_install.htm
- SFDX:https://developer.salesforce.com/platform/dx
- Cmdt Command : https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_force_cmdt.htm#cli_reference_force_cmdt
- Custom Metadata Type: http://resources.docs.salesforce.com/200/9/en-us/sfdc/pdf/custom_metadata_types_impl_guide.pdf
Make a one-time donation
Make a monthly donation
Make a yearly donation
Choose an amount
Or enter a custom amount
Your contribution is appreciated.
Your contribution is appreciated.
Your contribution is appreciated.
DonateDonate monthlyDonate yearly
I am getting a generic deploy error when deploying source to org.
=== Deploy Errors
10:44:51.901 ended SFDX: Deploy Source to Org
LikeLiked by 1 person
Man, Iâm laughing out loud. I searched for how to massively import metadata. I found your page first, and itâs perfect. Then I realised that Iâm trying to import the exact same kind of information: country details related to phone numbers country code. Funny coincidence. Thanks for the excellent post!
LikeLiked by 1 person
since there is currently no export To do a round trip, here is a quick way to export:
sfdx force:data:soql:query -q âSELECT DeveloperName, FIELDS(CUSTOM) FROM MyData__mdt LIMIT 200â âresultformat csv > scripts/data/MyData__mdt.csv
Caveat: you will need to change the row1, col1 DeveloperName label to Name
LikeLiked by 1 person