You need to sign in to do that
Don't have an account?
fiona gentry
My test class shows Failed,please help in fixing
Hi Gurus,
have writtern the apex aura enabled controller for controller and also the test class,please help me in fixing and writing detailed test class for below upsert apex class
apex controller
Here is error while running test class
Your help is needed and appreciated
Fiona
have writtern the apex aura enabled controller for controller and also the test class,please help me in fixing and writing detailed test class for below upsert apex class
apex controller
public class PickListHandler { @AuraEnabled public static List<LavelWrapper> getLevel1(string recID){ List<String> tempLst1 = new List<String>(); list<LavelWrapper> lstWrap=new list<LavelWrapper>(); // System.debug('recid'+recID); list<ERT_Case_Type__c> lstertcase=new list<ERT_Case_Type__c>(); lstertcase=[select id,Level_1__c,Level_2__c,Level_3__c from ERT_Case_Type__c where id=:recID];//fetch data based on it string strL1,strL2,strL3; if(lstertcase.size()>0){ strL1=lstertcase[0].Level_1__c; strL2=lstertcase[0].Level_2__c; strL3=lstertcase[0].Level_3__c; } // System.debug(strL2+'recid'+strL1); for(AggregateResult ar : [select Level_1__c,COUNT(id) from Case_Type_Data__c group by Level_1__c]) { LavelWrapper obj= new LavelWrapper(); string strLav1=(string)ar.get('Level_1__c'); obj.strLavelType='recL1'; obj.strL1val=strLav1; if(strLav1==strL1) obj.isSelected=true; else obj.isSelected=false; lstWrap.add(obj); //tempLst1.add(strLav1); } //get l2 data for(string ar:getLevel2(strL1)){ if(strL1!=null){ LavelWrapper obj= new LavelWrapper(); // string strLav2=(string)ar.get('Level_2__c'); string strLav2=(string)ar; obj.strLavelType='recL2'; obj.strL2val=strLav2; if(strLav2==strL2) obj.isSelected=true; else obj.isSelected=false; lstWrap.add(obj); } } //get l2 data for(string ar:getLevel3(strL1,strL2)){ if(strL2!=null){ LavelWrapper obj= new LavelWrapper(); // string strLav2=(string)ar.get('Level_2__c'); string strLav2=(string)ar; obj.strLavelType='recL3'; obj.strL3val=strLav2; if(strLav2==strL3) obj.isSelected=true; else obj.isSelected=false; lstWrap.add(obj); } } System.debug(' wrapper '+lstWrap); return lstWrap; } @AuraEnabled public static List<String> getLevel2(string strName){ List<String> tempLst2 = new List<String>(); for(AggregateResult ar : [select Level_2__c,COUNT(id) from Case_Type_Data__c where Level_1__c=:strName group by Level_2__c]) { tempLst2.add(''+ar.get('Level_2__c')); } return tempLst2; } @AuraEnabled public static List<String> getLevel3(string strName1,string strName2){ List<String> tempLst3 = new List<String>(); for(AggregateResult ar : [select Level_3__c,COUNT(id) from Case_Type_Data__c where Level_1__c=:strName1 and Level_2__c=:strName2 group by Level_3__c]) { tempLst3.add(''+ar.get('Level_3__c')); } return tempLst3; } @AuraEnabled public static String savecasetype(string level1,string level2,string level3,string id){ string strMsg='successfull'; try{ ERT_Case_Type__c obj=new ERT_Case_Type__c(); System.debug('CASE = '+ Obj.Case__c); Obj.Level_1__c=level1; System.debug('Level1 = '+ Obj.Level_1__c); Obj.Level_2__c=level2; System.debug('Level2 = '+ Obj.Level_2__c); Obj.Level_3__c=level3; System.debug('Level3 = '+ Obj.Level_3__c); if(id.startsWithIgnoreCase('500')) Obj.Case__c = id; else obj.id=id; upsert obj; } catch(Exception ex){ strMsg='error'; } return strMsg; } public class LavelWrapper{ @AuraEnabled public string strLavelType{get;set;} @AuraEnabled public string strL1val{get;set;} @AuraEnabled public string strL2val{get;set;} @AuraEnabled public string strL3val{get;set;} @AuraEnabled public boolean isSelected{get;set;} } }Here is test class
@IsTest public class testGetAllLevels { @IsTest static void testGetLevel1() { Case_Type_Data__c obj = new Case_Type_Data__c(); obj.Level_1__c = 'Test Level 1'; insert obj; List<String> s = PickListHandler.getLevel1(); } @IsTest static void testGetLevel2() { Case_Type_Data__c obj = new Case_Type_Data__c(); obj.Level_1__c = 'Test Level 1'; insert obj; List<String> s = PickListHandler.getLevel2('Test Level 1'); } @IsTest static void testGetLevel3() { Case_Type_Data__c obj = new Case_Type_Data__c(); obj.Level_1__c = 'Test Level 1'; obj.Level_2__c = 'Test Level 2'; obj.Level_3__c = 'Test Level 3'; insert obj; List<String> s = PickListHandler.getLevel3('Test Level 1','Test Level 2'); } @IsTest static void testsaveCaseType(){ // Create the Case Record. Case cas = new Case(Status ='New', Priority = 'Medium', Origin = 'Email'); insert cas; ERT_Case_Type__c obj=new ERT_Case_Type__c(); string one='one'; string two='two'; string three='three'; test.startTest(); String testing=PickListHandler.savecasetype(one,two,three,cas.id); test.stopTest(); } }
Here is error while running test class
== Test Summary NAME VALUE ─────────────────── ───────────────────────────────────── Outcome Failed Tests Ran 1 Pass Rate 0% Fail Rate 100% Skip Rate 0% Test Run Id 7072F00001g7Xqs Test Execution Time null ms === Test Results TEST NAME OUTCOME MESSAGE RUNTIME (MS) ────────────────────────── ─────────── ──────────────────────────────────────────────────────────────────────────────────────────────────────────────── ──────────── testGetAllLevels.<compile> CompileFail line 10, column 38: Method does not exist or incorrect signature: void getLevel1() from the type PickListHandler null
Your help is needed and appreciated
Fiona
The issue is at the following line
The method getLevel requires a string input so you should pass
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