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
Carolyn juliana 7Carolyn juliana 7 

How do i write test class for below apex code

Hi Gurus,

Please help me in writing test class for below apex code 
 
public class PickListHandler {
    @AuraEnabled
    public static List<String> getLevel1(string strName){
     
    
       List<String> tempLst = new List<String>();


    for(AggregateResult  ar : [select Level_1__c,COUNT(id) from Case_Type_Data__c  group by Level_1__c])
    {
    tempLst.add('Level 1 data is'+ar.get('Level_1__c'));
    }

 return tempLst;
      
      
    } 
   

}
Regards,
Carolyn
Best Answer chosen by Carolyn juliana 7
David Zhu 🔥David Zhu 🔥
static testMethod void testGetLevel1()
{
 Case_Type_Data__c data = new Case_Type_Data__c();
data.Level_1__c="test";
Insert data;
    List<String> s = PicklistHandler .getLevel1('test');
    //System.assert(....);
}

All Answers

David Zhu 🔥David Zhu 🔥
You can use the code below for reference

static testMethod void testGetLevel1()
{

    List<String> s = PicklistHandler .getLevel1('test');
    //System.assert(....);
}
Carolyn juliana 7Carolyn juliana 7
appreciate your response,problem is i see only 66% coverageUser-added image
David Zhu 🔥David Zhu 🔥
static testMethod void testGetLevel1()
{
 Case_Type_Data__c data = new Case_Type_Data__c();
data.Level_1__c="test";
Insert data;
    List<String> s = PicklistHandler .getLevel1('test');
    //System.assert(....);
}
This was selected as the best answer
Carolyn juliana 7Carolyn juliana 7
Hi David,could you help with this https://developer.salesforce.com/forums/ForumsMain?id=9062I000000QyFZQA0