• Alias Uchiha
  • NEWBIE
  • 10 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 0
    Replies
Please help me to cover the percantage for the below line of code:-

public class testing1 {
  @AuraEnabled
    public static List<String> getObjectName(){
 List<String> objects=new List<String>();
       List<Schema.SObjectType> gd = Schema.getGlobalDescribe().Values();  
        for(SObjectType sot:gd){
           objects.add(sot.getDescribe().getName());
           objects.sort();  
        }
        return objects;
    }
    
    @AuraEnabled
        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()){
                fieldList.add(fieldsMap.get(str).getDescribe().getName());                
            }
    return fieldList;
}
    
    
       @AuraEnabled
        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;
}
    
      @AuraEnabled
        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);
        System.debug(sobjType);
        Schema.DescribeSObjectResult describeResult = sobjType.getDescribe();
        Map<String,Schema.SObjectField> fieldsMap = describeResult.fields.getMap();
        Schema.DisplayType fielddataType = fieldsMap.get(fld11).getDescribe().getType();
        String a;
        System.debug(fielddataType);
       // return Schema.getGlobalDescribe().get(objIdd).getDescribe().fields.getMap().get(fldId).getDescribe().getType();
         System.debug('return ' +fielddataType);
        return String.valueOf(fielddataType);
        }
}

Thanks
I have to write test class for this in one test class:-

public static String getMethod(String name) {
        try {
                HttpRequest request = new HttpRequest();
                Http http = new Http();
                HttpResponse response = new HttpResponse();
                request.setMethod('GET');
                request.setEndpoint('https://any_endpoint_here.com');
                response = http.send(request);
                    Map<String, Object> JSONDataMap=(Map<String, Object>) JSON.deserializeUntyped(response.getBody());
                    return String.valueOf(JSONDataMap.get('status'));
                }
            }
        } catch (Exception e) {
            System.debug('Exception>>' + e.getMessage() + ' at Line Number>>' + e.getLineNumber());
        } return null;
    }
    
    @AuraEnabled
  public static String getMethod2(String name2) {
        try {
                HttpRequest request = new HttpRequest();
                Http http = new Http();
                HttpResponse response = new HttpResponse();
                request.setMethod('GET');
                request.setEndpoint('https://any_endpoint_here.com');
                response = http.send(request);
                    Map<String, Object> JSONDataMap=(Map<String, Object>) JSON.deserializeUntyped(response.getBody());
                    return String.valueOf(JSONDataMap.get('status'));
                }
            }
        } catch (Exception e) {
            System.debug('Exception>>' + e.getMessage() + ' at Line Number>>' + e.getLineNumber());
        } return null;
    }
    
    This is the sample code
    Anyone help me in this?
    Thanks