Usually, we can't insert or update Custom Metadata records using Apex with normal DML statements.
We have custom meta loader to insert or update multiple records into Custom Metadata.
- Download the tool from GitHub and deploy the package to your org via Workbench. Create the .zip file from the contents of the custom_md_loader directory instead of zipping up the directory itself.
- Create a .csv file with a header that contains the custom metadata type’s field API names. Either the Label or the Developer Name field is required. See sample.csv in your download for an example. If your org is namespaced, include the namespace prefix in your header. To update an existing custom metadata record, use the Label or Developer Name field to identify it.
- From Setup, assign the Custom Metadata Loader permission set to the appropriate users, including yourself.
- From the App Picker, select Custom Metadata Loader.
- Click the Custom Metadata Loader tab. If you haven’t already done so, the app prompts you to configure your Remote Site Settings.
- Upload your .csv file and select the corresponding custom metadata type.
- Click Create/Update custom metadata to bulk-load the records from the .csv file or update existing records. If the file has duplicate Label or Developer Name entries, the last entry becomes the new or updated record.