0

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:

force-app/main/default/customMetadata/

and not on

force-app/main/default/objects/...

Couldn't find anything useful in the documentation.

Please advise.

1
  • 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. Dec 19, 2020 at 2:56

2 Answers 2

3

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"

1

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.

1
  • 1
    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
    Jan 24 at 7:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.