I've created via the UI a custom metadata type, now I want to add records to it from a CSV using the sfdx CLI.

I tried the cmdt:record:insert command but I get the following error:

ENOENT: no such file or directory, scandir 'force-app/main/default/objects/My_Settings__mdt/fields'

Full command: sfdx force:cmdt:record:insert --filepath mdt_records.csv --typename My_Settings

(The mdt_records.csv file is saved in the project base folder, where I enter the command above)

I don't have an 'object' folder on my project, so I tried to pull the custom metadata hoping it will land in object folder but it was populated on:


and not on


Couldn't find anything useful in the documentation.

Please advise.

  • Have you pulled down the source after you added the Custom Metadata Type? The error is looking for the Custom Metadata Type definition file in that location. After creating the Custom Metadata Type in your scratch run a sfdx force:sorce:pull command first and then try this. Commented Dec 19, 2020 at 2:56

4 Answers 4


You can retrieve the MDT and fields using the CLI command

"sfdx force:source:retrieve -m CustomObject:MetaDateName__mdt"

Then use this CLI command to create the custom MDT xml files for the records that you have in the csv file

"sfdx force:cmdt:record:insert --filepath FileLocation:\FileName.csv --typename MetaDateName__mdt"


The below way worked for me while creating record first time The issue is with the file format. Just save your file in .txt format and check and make sure values in the header and all rows in ',' separated format. (Issue is sometimes header is in ',' separated and rows are in ';' separated, Or both in ';' separated) after correcting change the file format to .CSV. And don't include Label and DeveloperName columns just include the Name column instead.

Refer to Replace semicolons with commas in CSV data imports

After that run

sfdx force:cmdt:record:insert -f filepath --typename custommetadata__mdt

If everything goes well it should create custom metadata files in your local, then simply right-click on them and deploy source to org.

When you have Metadata Relationship data type field in your custom metadata There is a known issue with "sfdx force:cmdt:record:insert" command: Using force:cmdt:record:insert generates XML with Metadata Relationship data types tagged as xsi:type="xsd:undefined". When deploying the resulting Custom Metadata Records the following error is received:

ERROR running force:source:deploy: Deploy failed

Replacing xsi:type="xsd:undefined" with xsi:type="xsd:string" fixes the issue.

And when you have more files to replace utilise VScode 'Find in Folder' feature then replace all.

  • 2
    Thanks, I needed to change vscode settings on how to validate xml file as well => Go to VS Code: Code => Preference => Settings => (search for) Validation ==> Click on XML (from the left Nav) and Uncheck "Validation" (salesforce.stackexchange.com/questions/328542/…)
    – Jojosfdc
    Commented Jan 24, 2022 at 7:58

I have the answear: Steps: Step1: go to terminal of vscode and run this command: sfdx force:cmdt:record:insert --filepath abc.txt --type-name custom__mdt -n dev

Note: dev columns does not exist in the custom metadata it's just for having a developer name in xml you will see this after

step2: add dev at the end of your csv content file like a1__c,a2__c,dev 1,1,X1 The line 1 will have X1 as developername

You have to put all custom columns field of your custommetadata (even if they are null or empty) step3: vs code will give you this success message : Created custom metadata type records from 'abc.txt' at 'force-app\main\default\customMetadata'. step4: go to check you xml records created step5: deploy to org you files (one by one or all the folder) check the content if the xml files has undefined , so you forgot one column from your custom metadata ass it as empty like replace undefined undefined by a3__c , after you go to salesforce to check your records


I decided to use the Custom Metadata Loader from the AppExchange.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .