+ 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.
    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; 
        Metadata.DeployContainer mdContainer = new Metadata.DeployContainer();
        UpdateMetadataUtil callback = new UpdateMetadataUtil();
        Id jobId = Metadata.Operations.enqueueDeployment(mdContainer, callback);