+ Start a Discussion
SFDC INSFDC IN 

Test Class for custom Metadata

Hi folks,

I am stuck with increasing the code coverage for the below Trigger. The Trigger uses the custom metadata for activation.

trigger testTrigger on customObject (after insert) {
    if(!TriggerActivationClass.checkActivationStatus('testTrigger')){
        return;
    }
    
    if(Trigger.isAfter && Trigger.isInsert){
         testTriggerHandler.someMethod(Trigger.New);    
    }
}


Below is the TriggerActivationClass class:

public with sharing class TriggerActivationClass {
    
    public static boolean checkActivationStatus(String str){
        Boolean defaultValue = false;
        Map<String,Boolean> result = new Map<String,Boolean>();
        if(Schema.customMetadata__mdt.getSObjectType().getDescribe().isAccessible()){
            customMetadata__mdt[] triggerActivation = [Select isActive__c, DeveloperName, MasterLabel from customMetadata__mdt];
            
            if(triggerActivation!= null && !triggerActivation.isEmpty()){
                for(customMetadata__mdt ta : triggerActivation){
                    result.put(ta.DeveloperName, ta.isActive__c); 
                }        
                return result.get(str);
            }  
        }                
        return defaultValue;
    }
}


I am stuck with writing the test class for the below code from the above trigger:

if(!TriggerActivationClass.checkActivationStatus('testTrigger')){
        return;


If anyone can help?

Thanks.