Import records for custom Metadata type Objects

Salesforce Data Loader doesn't support import data to custom metadata type of object. but sometimes we need to create bulk amount of records for custom metadata. here is the workaround to import custom metadata to org using vs code and  salesforce cli.

Import csv data to custom metadata

Step: 1 

Create a custom metadata object and its' fields in your org. 
In this example, we have created custom metadata object: Country Names with codes. to store the country name, we are using standard Name field and for country code , created new field Country code
country-metadata

Step: 2

Open your vs code and authenticate your org with salesforce cli. 

Step: 3

Retrieve your custom metadata object and fields you have created in step 1. Run the below command on vs code terminal to get object and its' fields. change object name in that command.
sfdx force:source:retrieve -m CustomObject:Country_Name_With_Code__mdt
retrieve-object
step: 4
Prepare your  .csv file having data to import. here i'm using standard name field and country code field.
import-file

Step: 5

Run the following command to create metadata records in your local. we can't directly import data to org, so using this salesforce command we will create records in local vs code customMetadata directory.
sfdx force:cmdt:record:insert --csv countries.csv --type-name Country_Name_With_Code__mdt
metadata-records

Step: 6

Now, we can deploy locally created records to org. Run the following command to import custom metadata records to org. 
sfdx force:source:deploy -m CustomMetadata
now check in your org having all the record.
custom-metadata-records
Labels:
Join the conversation