Custom Metadata: Mass Insert Custom Metadata Type Records



In Salesforce, you cannot directly mass insert Custom Metadata Type (CMDT) records using normal data tools like Data Loader or Data Import Wizard. This is mainly due to how Salesforce treats Custom Metadata.

1. Custom Metadata is considered Metadata, not Data

Custom Metadata records are stored as metadata configuration, similar to objects, fields, and workflows.
Because of this, Salesforce expects them to be deployed through metadata deployment tools, not data tools.


2. They are packageable and deployable

  1. Custom Metadata is designed to be moved between orgs (Dev → Test → Prod).
  2. Allowing normal bulk inserts could break the configuration consistency between environments.

3. Limited CRUD operations

  1. You cannot insert/update/delete CMDT records using standard DML in Apex (except with the Metadata API).
  2. Only read operations are allowed normally.

4. Supported ways to insert multiple CMDT records

You can mass-create them using:

  1. Metadata API (recommended for bulk)
  2. Apex Metadata API
  3. Deployment via Change Sets or Packages
  4. SFDX / Salesforce CLI deployment
  5. Workbench → Metadata API

Example approaches

  1. Deploy a CSV converted into metadata XML
  2. Use the SFDX command to deploy CMDT records
  3. Use the Apex Metadata API for runtime creation


Using SalesforceDX CLI:
https://sfdclesson.com/2021/02/20/mass-insert-custom-metadata-type-records/

Using External Tool:
https://www.packmagix.com/#
Post a Comment (0)
Previous Post Next Post