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
Alias UchihaAlias Uchiha 

I want to write test class for this functions

Please help me to cover the percantage for the below line of code:-

public class testing1 {
    public static List<String> getObjectName(){
 List<String> objects=new List<String>();
       List<Schema.SObjectType> gd = Schema.getGlobalDescribe().Values();  
        for(SObjectType sot:gd){
        return objects;
        public static List<String> getAllFields(String fld){
        List<String> fieldList = new List<String>();
Map<String,Schema.SObjectType> gd = Schema.getGlobalDescribe();
Schema.SObjectType sobjType = gd.get(fld);
Schema.DescribeSObjectResult describeResult = sobjType.getDescribe();
Map<String,Schema.SObjectField> fieldsMap = describeResult.fields.getMap();
    for(string str: fieldsMap.keySet()){
    return fieldList;
        public static String getAllFieldsName(String fld1, String fld2){
       String ObjectName= fld2;
             system.debug('ObjectName '+ObjectName);
            String FieldName= fld1;
            system.debug('FieldName '+FieldName);
             system.debug('FieldName '+Schema.getGlobalDescribe().get(ObjectName).getDescribe().fields.getMap().get(FieldName).getDescribe().getLabel());
        return Schema.getGlobalDescribe().get(ObjectName).getDescribe().fields.getMap().get(FieldName).getDescribe().getLabel();
            //  Schema.DisplayType fielddataType;
      //      return  fielddataType.Schema.getGlobalDescribe().get(FieldName).getDescribe().getType();    
       // List<String> fieldList = new List<String>();
//Map<String,Schema.SObjectType> gd = Schema.getGlobalDescribe();
//Schema.SObjectType sobjType = gd.get(fld1);
//Schema.DescribeSObjectResult describeResult = sobjType.getDescribe();
//Map<String,Schema.SObjectField> fieldsMap = describeResult.fields.getMap();
   // for(string str: fieldsMap.keySet()){
        //        fieldList.add(fieldsMap.get(str).getDescribe().getName());                
     //       }
 //   return fieldList;
            //Schema.SObjectField F = fieldNameMap.get(fieldAPIName); //where fieldAPIName is API name of field
//Schema.DescribeFieldResult R = F.getDescribe();
//String fieldLabel=R.getLabel();
//return fieldLabel;
        public static String getAllFieldsDataType(String fld11, String fld12){
     Map<String,Schema.SObjectType> gd = Schema.getGlobalDescribe();
        //String ac='Account';
        System.debug('sObject' +fld12);
        System.debug('fieldname' +fld11);
        Schema.SObjectType sobjType = gd.get(fld12);
        Schema.DescribeSObjectResult describeResult = sobjType.getDescribe();
        Map<String,Schema.SObjectField> fieldsMap = describeResult.fields.getMap();
        Schema.DisplayType fielddataType = fieldsMap.get(fld11).getDescribe().getType();
        String a;
       // return Schema.getGlobalDescribe().get(objIdd).getDescribe().fields.getMap().get(fldId).getDescribe().getType();
         System.debug('return ' +fielddataType);
        return String.valueOf(fielddataType);

AnudeepAnudeep (Salesforce Developers) 
Hi Alias, 

I see that you have @AuraEnabled methods

Posting here an example of how to test AuraEnabled methods. Hope it helps
public static String TestController(String username, String password) {
    try {
        String name = username;
        String pass = password;
        if(name == 'test@test.test' && pass == 'pass')
            return 'true';
    catch (Exception ex) {
        return ex.getMessage();

Test Class
private class lightningForgotPasswordControllerTest
    static void TestForgotPassword()
        String result = LightningForgotPasswordController.TestController('test@test.test', 'pass');
        System.assertEquals(null, result);

Let me know if this helps, if it does, please mark this answer as best so that others facing the same issue will find this information useful. Thank you
Akshay Dhiman 63Akshay Dhiman 63
Hi Allas,

Below test class works fine please this out:-

private class testclassForTesting {
    @isTest static void  testCallout(){
        System.assertEquals('Account Name',testing1.getAllFieldsName('Name','Account'));

Hope this explanation will resolve your query. Mark it as the best answer if you find it helpful.