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 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 that 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 creation/definition steps.

Setup> Quick find> search ‘custom metadata’ and click on “New Custom Metadata Type”.

Create the Custom Metadata Type and fields.

Custom Metadata Type

Open your VSCODE IDE and create a project (If you already have 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 icon Retrieve Source From Org on ‘Custom Object’.

Org Browser

Here I am using ‘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 same as fields 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 “Name” (Label) field replace with 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 the all custom metadata type records that have been created in your local machine in project folder.

Right click on 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 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.

Reference: