Mass Insert Custom Metadata Type Records

Mass Insert Custom Metadata
Type Records

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.

Custom Metadata Type
Advertisements

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’.

Org Browser

Here I am using the ‘Org Browser’ extension to fetch the metadata information from Salesforce org.

Advertisements

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.

Advertisements

Mass Insert Custom Metadata Type Records

Reference:

Advertisements

Arun Kumar

Arun Kumar is a Salesforce Certified Platform Developer I with over 7+ years of experience working on the Salesforce platform. He specializes in developing custom applications, integrations, and reports to help customers streamline their business processes. Arun is passionate about helping businesses leverage the power of Salesforce to achieve their goals.

This Post Has 6 Comments

  1. tomtam6

    I am getting a generic deploy error when deploying source to org.
    === Deploy Errors
    10:44:51.901 ended SFDX: Deploy Source to Org

  2. Marc

    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!

  3. Tom S

    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

  4. vishal

    Getting below everytime I try to import

    Error (1): Cannot read properties of undefined (reading ‘replace’)

    1. Abhijit

      Hi Did u get any solution to this?

Leave a Reply