+ Start a Discussion
NK ShaNK Sha 

Export Data controller Test class

Hi All
Can any one help me on this
How to write the Test class for Export Data Controller

public class ExportDataCntrlPage {
  @AuraEnabled
    public static List<String> listAllObject(){
        List<String> objectList = new List<String>();
        For(Schema.sObjectType sobj: schema.getGlobalDescribe().values()){
            if(sobj.getDescribe().isQueryable())
              objectList.add(sobj.getDescribe().getName()+'####'+sobj.getDescribe().getLabel());
        }
        system.debug('objectlist: '+objectList);
        return objectList;
    }
    
    @AuraEnabled
    public static List<fieldDataWrapper> listAllFields(String objectName){
        List<fieldDataWrapper> wrapperList =  new List<fieldDataWrapper>();
        // Create Dynamic Query Start ..
        String theQuery = 'SELECT ';
        system.debug('select: '+theQuery);
        SObjectType sObjectName = Schema.getGlobalDescribe().get(objectName);
        system.debug('object Name: '+sObjectName);
        Map<String,Schema.SObjectField> mfields = sObjectName.getDescribe().fields.getMap();
        For(Schema.SObjectField field : mfields.values()){
            
               fieldDataWrapper wrapper = new fieldDataWrapper();
               theQuery += field.getDescribe().getName() + ',' ;
                wrapper.label = field.getDescribe().getLabel();
                wrapper.apiName = field.getDescribe().getName();
            
                wrapperList.add(wrapper);
            system.debug('wraplist:'+wrapperList);
            
        }
        return wrapperList;
        
    }
    
    public class fieldDataWrapper{
        @AuraEnabled
        public String label { get; set; }
        @AuraEnabled
        public String apiName { get; set; }
    }
}
Best Answer chosen by NK Sha
Arun pattnaik 17Arun pattnaik 17
Hi,

@isTest
public class Data_Controller_Test {
    public static testmethod void testlistAllObject()
    {
       List<String> res= Data_Controller_ForTest.listAllObject();
        System.assert(res!=null,true);
        system.AssertNotEquals(0,res.size());
    }
    
     public static testmethod void testlistAllFields()
    {
        Data_Controller_ForTest.fieldDataWrapper fdw=new Data_Controller_ForTest.fieldDataWrapper();
        List<Data_Controller_ForTest.fieldDataWrapper> res= Data_Controller_ForTest.listAllFields('Opportunity');
        System.assert(res!=null,true);
        system.AssertNotEquals(0,res.size());
    }
}