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.
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’.
Here I am using the ‘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 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.
Mass Insert Custom Metadata Type RecordsTweet
- ANT tool: https://developer.salesforce.com/docs/atlas.en-us.daas.meta/daas/forcemigrationtool_install.htm
- Cmdt Command : https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_force_cmdt.htm#cli_reference_force_cmdt
- Custom Metadata Type: http://resources.docs.salesforce.com/200/9/en-us/sfdc/pdf/custom_metadata_types_impl_guide.pdf