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
Kristiana GrangerKristiana Granger 

Test class - How to cover method which returns list of records from metadata,

Here is code 
 public static List<RetentionPlan__mdt> fetchAllData() {
        List<RetentionPlan__mdt> dataList = [Select id, Order__c , 
                                                       Retain__c, Limit__c,
                                                      SobjectAPIName__c ,                                                     SobjectAPIName__r.QualifiedApiName,
                                                       Where__c 
                                                       FROM RetentionPlan__mdt 
                                                    WHERE isActive__c = true];

        return dataList;   
    }
    
   public static void operationDataStorageReduction(List<sobject> scope) {
        Database.delete(scope, false);
    }
---------------------------
So basicaly these two methods get call from batch class, (Delete records) Can any one guide me how to write testclass for these 2
Devi ChandrikaDevi Chandrika (Salesforce Developers) 
In test classes no need to create custom metadata.W can access them by default.
Try this code.
@istest static void testm(){
        className.fetchAllData();//Replace your classname
         
         
    list<account> acc = new list<account>();
    account a = new account();
    a.name = 'hiii';
    acc.add(a) ;//insert any sobject record
    insert acc;
    
    className.operationDataStorageReduction(acc);
    }

Hope this helps you
Let me know if this helps you. Kindly mark it as solved so that it may help others in future.

Thanks and Regards