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
abcdef12345abcdef12345 

Need help in Test class for selected options

public class dynamicApex5 {

   public list<SelectOption> selectedobject { get; set; }

    public String objectName { get; set; }    
    public set<string> flds{get;set;}
    
    Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
    public dynamicApex5(){
                   
                selectedobject = new list<SelectOption>();  
                  selectedobject.add(new selectoption('','-None-'));
                  list<schema.SobjectType> lst=schemaMap.values();
                  for(schema.SobjectType ss:lst){
                      selectedobject.add(new selectoption(ss.getDescribe().getLocalName(),ss.getDescribe().getLabel()));
                      selectedobject.sort();
               }
                 flds= new set<string>();
                  lsps=new list<SelectOption>();
    }
 
      
      public String fields { get; set; }
      
       public list<SelectOption> lsps{get;set;}
      
       public void function() {
       
         if(objectName!=null || objectName!=''){
           Map<string,Schema.SObjectField> mpConField=schemaMap.get(objectName).getDescribe().fields.getMap();
               flds=mpConField.keySet();
                                
                   for(string name:flds){
                   Schema.DescribeFieldResult fldResult=mpConField.get(name).getDescribe();
                    lsps.add(new SelectOption(fldResult.getName(),fldResult.getName()));
                    lsps.sort();                    
                   }
                }        
    }
    
        

}
Best Answer chosen by Admin (Salesforce Developers) 
asish1989asish1989

Hi

This is the test class having 100 percent code coverage.

@isTest
private class MileageTrackerTestSuite {

    static testMethod void runPositiveTestCases() {
        dynamicApex5 testclss = new dynamicApex5();
        testclss.objectName = 'Account';
        testclss.function();
    }
    
}    

 Did this post answers your question, if so please mark it solved .

 

 Thanks

 

All Answers

MartinHaagenMartinHaagen

Hi,

 

could you elaborate please? 

asish1989asish1989

Hi

This is the test class having 100 percent code coverage.

@isTest
private class MileageTrackerTestSuite {

    static testMethod void runPositiveTestCases() {
        dynamicApex5 testclss = new dynamicApex5();
        testclss.objectName = 'Account';
        testclss.function();
    }
    
}    

 Did this post answers your question, if so please mark it solved .

 

 Thanks

 

This was selected as the best answer