4
votes

I have a custom metadata type "Project Literals" which have records that contain custom field ids

example: Label: StatusFieldId Name: StatusFieldId Id Field: 00N8E000000XYuM

Using DML statements give me an error "Id Field is not writable"

Is there a way to update the value using apex? maybe by using Metadata API, but how?

2
Can you please provide the snippet of code to understand what you're trying to achieve? - vladykx

2 Answers

5
votes

From the Custom Metadata Types Implementation Guide (page 9, emphasis mine):

Access Custom Metadata Types and Records

Use SOQL to access your custom metadata types and to retrieve the API names of the records on those types. DML operations aren’t allowed on custom metadata in Apex, the Partner APIs, and Enterprise APIs.

2
votes

To make DML-like operations, you might also be interested in the apex/visualforce Custom Metadata Loader by Salesforce. It's open source on GitHub and has to make use of the Metadata API behind the scenes.

Related question: https://salesforce.stackexchange.com/questions/110482/can-we-update-records-of-custom-metadata-type-in-visualforce-page