function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
mysteriousauramysteriousaura 

Insert records to a custom metadata type: Field is not writeable:

Hi,
I am trying to create records in a Custom MetaDataType using https://github.com/financialforcedev/apex-mdapi. But when I create a list to use a method CustomMetadataService.createMetadata I get an error Compile Error: Field is not writeable: NAMESPACE__TestRetention__mdt.DeveloperName at line 53

Here is my code
        List< NAMESPACE__TestRetention__mdt > newList = new List< NAMESPACE__TestRetention__mdt >();
        for(NAMESPACE__TestRetention__mdt s: newList)
        {
            s.developername='New';
            s.label='New';
            s.masterlabel='New';
            s.qualifiedapiname='New';
            newList.add(s);
        }
       CustomMetadataService.createMetadata(newlist); 

How do I create data for inserting it into the method if I cant insert it to a list?
KevinPKevinP
have you tried running that code without setting the developername?
Daniel BallingerDaniel Ballinger
You can't currently manipulate Custom Metadata Types from Apex as they are considered metadata. See Insert Custom Metadata for Unit Test (http://salesforce.stackexchange.com/q/111375/102)

Consider voting for Custom MetaData Types need APEX methods to access/update (https://success.salesforce.com/ideaView?id=0873A000000lD5pQAE)