Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can Apex update Custom Metadata Types records/Literals values?

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?

like image 691
James Azaña Avatar asked Mar 12 '23 17:03

James Azaña


2 Answers

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.

like image 144
Adrian Larson Avatar answered Mar 19 '23 11:03

Adrian Larson


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

like image 39
Doug Ayers Avatar answered Mar 19 '23 13:03

Doug Ayers