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
Puspendra SinghPuspendra Singh 

Test Class for a trigger that insert record in custom metadata object using Metadata.DeployCallback interface

Hello Experts,

I have a situation where i need to insert a record in custom metadata object using apex trigger. I have written the trigger and it is working fine. 
Now since i need to move the code into production, i have to write a test class for this. Can someone please suggest how should i write this test class.
Here is my class that is being called from trigger

Public class UpdateMetadataUtil implements Metadata.DeployCallback {
    
    public void handleResult(Metadata.DeployResult result, Metadata.DeployCallbackContext context) {
        if (result.status == Metadata.DeployStatus.Succeeded) {
            System.debug(' success : '+ result);
        } else {
            System.debug(' fail : '+ result);
        }
    }
    
    //Method to update Integration_Credential.PO_Header_NBS Custom Metadata record.
    @future
    public static void UpdateMetadata(String headerMap){
        Metadata.CustomMetadata customMetadata =  new Metadata.CustomMetadata();
        customMetadata.fullName = 'Integration_Credential.PO_Header_NBS';
        customMetadata.label = 'PO Header NBS';
        Metadata.CustomMetadataValue customField = new Metadata.CustomMetadataValue();
        customField.field = 'HeaderMap__c';
        customField.value = headerMap; 
        customMetadata.values.add(customField); 
        Metadata.DeployContainer mdContainer = new Metadata.DeployContainer();
        mdContainer.addMetadata(customMetadata);
        UpdateMetadataUtil callback = new UpdateMetadataUtil();
        Id jobId = Metadata.Operations.enqueueDeployment(mdContainer, callback);
    }