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
Vishal Ranjan 14Vishal Ranjan 14 

DML operation Update not allowed

Hi All, I am getting error "DML operation Update not allowed on" while updating custom metadata type record through my apex class. Please let me know if we can update custom metadata type records or not?
learn1.3947400898749973E12learn1.3947400898749973E12
Hi,

Please check if your SOQL queries Id field before you make dml operation
Vishal Ranjan 14Vishal Ranjan 14
Hi,

please explain in more detail about your approach.
Raj VakatiRaj Vakati


You can not able to update the custom metadata type in apex .. If you want to update the custom metadata type you need to use Metadata API


Refer this link

https://ashwanisoni.wordpress.com/2017/05/02/create-or-update-custom-metadata-type-via-apex-code-salesforce-summer-17/
// Set up custom metadata to be created in the subscriber org.
    Metadata.CustomMetadata customMetadata =  new Metadata.CustomMetadata();
    customMetadata.fullName = 'Response_Type.Not_Found_Code';
    customMetadata.label = 'Not_Found_Code';

    Metadata.CustomMetadataValue customField = new Metadata.CustomMetadataValue();
    customField.field = 'Status_Code__c';
    customField.value = '404';

    customMetadata.values.add(customField);

    Metadata.DeployContainer mdContainer = new Metadata.DeployContainer();
    mdContainer.addMetadata(customMetadata);

    // Setup deploy callback, MyDeployCallback implements
    // the Metadata.DeployCallback interface (code for
    // this class not shown in this example)
    CustomMetadataCallback callback = new CustomMetadataCallback();

    // Enqueue custom metadata deployment
    // jobId is the deployment ID
    Id jobId = Metadata.Operations.enqueueDeployment(mdContainer, callback);

i..

 
Vishal Ranjan 14Vishal Ranjan 14
Hi Raj,

This is useful to create a new record and deploy same.

But, as per my requirement I need to udpate a existing custom metadata type record. Do you have code for that?