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
Rahul Jain 238Rahul Jain 238 

Can anyone help me in writting a test class for this method

@AuraEnabled
    public static List<String> getPicklistvalues(String objectName, String field_apiname,Boolean nullRequired){
        List<String> optionlist = new List<String>();       
        Map<String,Schema.SObjectType> gd = Schema.getGlobalDescribe(); 
        Map<String, Schema.SObjectField> field_map = gd.get(objectName.toLowerCase()).getDescribe().fields.getMap();        
        List<Schema.PicklistEntry> picklistValues = field_map.get(field_apiname).getDescribe().getPickListValues();       
        if(nullRequired == true){
            optionlist.add('--None--');
        }       
        for (Schema.PicklistEntry pv : picklistValues) {
            optionlist.add(pv.getValue());
        }
        return optionlist;
    }
Best Answer chosen by Rahul Jain 238
Dushyant SonwarDushyant Sonwar
Call the method with class name..
YourClassName.getPicklistvalues('Account' , 'Type' , true);
 
@isTest
Public class TestPicklistValues{
	static testMethod void unitTest(){
		YourClassName.getPicklistvalues('Account' , 'Type' , true);
	}
}

 

All Answers

Dushyant SonwarDushyant Sonwar
Call the method with class name..
YourClassName.getPicklistvalues('Account' , 'Type' , true);
 
@isTest
Public class TestPicklistValues{
	static testMethod void unitTest(){
		YourClassName.getPicklistvalues('Account' , 'Type' , true);
	}
}

 
This was selected as the best answer
Rahul Jain 238Rahul Jain 238
Thanks Dushyant Sonwar