Skip to main content
Priti Gohil (PwC) a posé une question dans #Apex
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
1 réponse
  1. 9 avr. 2020, 04:52
    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