• Carolyn juliana 7
  • NEWBIE
  • 110 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 14
    Questions
  • 8
    Replies
How to create a truncated version of field for 255 characters for existing data or Historical data,for new and updated data i have the solution mentioned here  (https://developer.salesforce.com/forums/ForumsMain?id=9062I000000Qz0BQAS)

I am interested to do a global update for the new 255 char field?Possible?

Regards,
Carolyn
Hi Gurus,

Our BI team can't pull in our description field from Cases because it's too long.   and we need to created a truncated version of this field for 255 characters

my question is what's the best way to do this?  on existing data and new data

Regards,
carolyn
 
Hi Gurus,

So  the issue is that  i can only add 1 join table to Cases. 
 ex. Case Types but I want both CaseTypes and ERT Case Types joined to Cases so i can report on all at once

For cases I have 2 custom objects one is Case Types which is for Legacy case types  and for new case types i have another cusotm object called ERT Case types
  
  When i Go to Reports>>New Report>>Choose Report Type i see 2 objects 
  
 A) Case with Case Types and,
 B) Cases with ERT Case types
User-added image
 
 Now when i got Setup>>Report types and when i try to create a new Report type and select primary as Cases 
 then it looks like looks like i can only have 1 B joined to A and not 2 Bs as shown below
User-added image

I need a report type such that to join  both CaseTypes and ERT Case Types joined to Cases so i can report on all at once

Regards,
Carolyn
Dear Gurus,

This is about a Apex DML exception which is troubling
23:43:49:014 EXCEPTION_THROWN [49]|System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Level 1, Case]: [Level 1, Case]

Here is apex code-->
public class PickListHandler {
    @AuraEnabled
    public static List<String> getLevel1(){
    List<String> tempLst1 = new List<String>();
        for(AggregateResult  ar : [select Level_1__c,COUNT(id) from Case_Type_Data__c  group by Level_1__c])
    {
        tempLst1.add(''+ar.get('Level_1__c'));
    }

    return tempLst1;
      
      
    } 
    
    @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 caseid){
     string strMsg='successfull';
          try{
     ERT_Case_Type__c obj=new ERT_Case_Type__c();
     Obj.Case__c =caseid;
     Obj.Level_1__c=level1;
     Obj.Level_2__c=level2;
     Obj.Level_3__c=level3;
     Insert obj;
     Return 'Successfully Inserted Levels';
     }
     
    catch(Exception ex){
            strMsg='error';
        }
     return strMsg;  
}
    
     
    
    

}

Hereis working Test class for above apex-->
@isTest
public class testGetAllLevels { 

static testMethod 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();

}
    
static testMethod 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');

}
    
static testMethod 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');

}
    
    
static testMethod 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 lightning component JS -->
({
    doInit : function(component, event, helper) {
        var action = component.get("c.getLevel1");
        action.setCallback(this, function(e) {
            if(e.getState()=='SUCCESS'){
                var result=e.getReturnValue();
                component.set("v.lstLevel1",result);
            }
        });
        $A.enqueueAction(action);
    },    
    getLvl1:function(component, event, helper){
       
        var picklist=component.find('ddLevel1');
        var picklistvalue=picklist.get('v.value');
        var action = component.get("c.getLevel2");
        //alert('called'+picklistvalue);
        action.setParams({  'strName' : picklistvalue  });//
        action.setCallback(this, function(e) {
            if(e.getState()=='SUCCESS'){
                var result=e.getReturnValue();
                component.set("v.lstLevel2",result);
            }
        });
        $A.enqueueAction(action);
        //  alert(picklistvalue);
    },
    getSelectedValue:function(component, event, helper){
        var picklist=component.find('ddLevel1');
        var picklistvalue=picklist.get('v.value');
        var picklistdep=component.find('ddLevel2');
        var picklistvaluedep2=picklistdep.get('v.value');
        var action = component.get("c.getLevel3");
       // alert(picklistvaluedep2+' called'+picklistvalue);
        action.setParams({  'strName1' : picklistvalue,
                         'strName2' : picklistvaluedep2});//
        action.setCallback(this, function(e) {
            if(e.getState()=='SUCCESS'){
                var result=e.getReturnValue();
                component.set("v.lstL3",result);
            }
        });
        $A.enqueueAction(action);
       // alert(picklistvalue+'  '+picklistvaluedep);
    },
    onConfirm:function(component, event, helper){
        var picklist=component.find('ddLevel1');
        var picklistvalue=picklist.get('v.value');
        var picklistdep=component.find('ddLevel2');
        var picklistvaluedep2=picklistdep.get('v.value');
       
        var picklistdep3=component.find('ddLevel3');
        var picklistvaluedep3=picklistdep3.get('v.value');
        var action = component.get("c.savecasetype");
        
        action.setParams({  'strName1' : picklistvalue,
                          'strName2' : picklistvaluedep2,
                          'strName3' : picklistvaluedep3,
                          'id' : component.get("v.recordId")});//
                          
        
        var toastEvent = $A.get("e.force:showToast");
       //alert('abcd');
        action.setCallback(this, function(e) {
            if(e.getState()=='SUCCESS'){
                var result=e.getReturnValue();
                // alert(result);
                if(result==='successfull'){
                    toastEvent.setParams({
                        "title": "Success!",
                        "message": "The record has been inserted  successfully."
                    });
                    toastEvent.fire();
                }else{
                    toastEvent.setParams({
                        "title": "Error",
                        "message": "The record has not been inserted  successfully."
                    });
                    toastEvent.fire();
                }
            }
        });
        $A.enqueueAction(action);
       
    }
})

Here is Apex handler -->
<aura:component controller="PickListHandler" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    <!-- Actions-->
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
    <!-- variable-->
    <aura:attribute name="lstLevel1" type="String[]" />
     <aura:attribute name="lstLevel2" type="String[]" />
      <aura:attribute name="lstL3" type="String[]" />
    <span> Level 1</span>
    <ui:inputSelect aura:id="ddLevel1" change="{!c.getLvl1}">
        <ui:inputSelectOption label="-Select-" value="true"/>        
        <aura:iteration items="{!v.lstLevel1}" var="value">          
            <ui:inputSelectOption label="{!value}" text="{!value}" />
        </aura:iteration>
    </ui:inputSelect>
    <span>Level 2</span>
    <ui:inputSelect aura:id="ddLevel2" change="{!c.getSelectedValue}">
        <ui:inputSelectOption label="-Select-" value="true"/>        
        <aura:iteration items="{!v.lstLevel2}" var="value">          
            <ui:inputSelectOption label="{!value}" text="{!value}" />
        </aura:iteration>
    </ui:inputSelect>
     <span>Level 3</span>
    <ui:inputSelect aura:id="ddLevel3" >
        <ui:inputSelectOption label="-Select-" value="true"/>        
        <aura:iteration items="{!v.lstL3}" var="value">          
            <ui:inputSelectOption label="{!value}" text="{!value}" />
        </aura:iteration>
    </ui:inputSelect>
    <lightning:button variant="brand" label="Save" onclick="{!c.onConfirm}" />
</aura:component>
Now when i run test class basically create a case and pass the id to apex class,i see no issues but issue comes only when i click 'Save',i see ""The record has not been inserted successfully."" On checking Logs i found DML exception as below
23:43:49:014 EXCEPTION_THROWN [49]|System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Level 1, Case]: [Level 1, Case]

Please note in this scenarion Each case can have multiple ERT_Case_Type__c and each ERT_Case_Type__c can have multiple Case_Type_Data__c

Please help in finding  resolution.

Thanks in Advance
Carolyn
 
i am having 90% code coverage because atch block is not covered,can anyone help in writing code for catch block as well

Apex code -->
public class PickListHandler {
    @AuraEnabled
    public static List<String> getLevel1(){
    List<String> tempLst1 = new List<String>();
        for(AggregateResult  ar : [select Level_1__c,COUNT(id) from Case_Type_Data__c  group by Level_1__c])
    {
        tempLst1.add(''+ar.get('Level_1__c'));
    }

    return tempLst1;
      
      
    } 
    
    @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 caseid){
     string strMsg='successfull';
          try{
     ERT_Case_Type__c obj=new ERT_Case_Type__c();
     Obj.Case__c =caseid;
     Obj.Level_1__c=level1;
     Obj.Level_2__c=level2;
     Obj.Level_3__c=level3;
     Insert obj;
     Return 'Successfully Inserted Levels';
     }
     
    catch(Exception ex){
            strMsg='error';
        }
     return strMsg;  
}

}

Test class code -->
@isTest
public class testGetAllLevels { 

static testMethod 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();

}
    
static testMethod 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');

}
    
static testMethod 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');

}
    
    
static testMethod 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();
    }
    
 
    
}

Thanks in advance
Carolyn
Hi Team,

appreciate your help,please help me in completing the test class for below
 
public with sharing class saveCaseType {
     
     @AuraEnabled
     Public  static ERT_Case_Type__c  savecasetype(string level1,string level2,string level3,string caseid){
     ERT_Case_Type__c obj=new ERT_Case_Type__c();
     Obj.Id =caseid;
     Obj.Level_1__c=level1;
     Obj.Level_2__c=level2;
     Obj.Level_3__c=level3;
     Insert obj;
     return obj;
     }
    
    
    

}

Thanks in Advance
Carolyn​​​​​​​
Hi,
I am getting this error for this code ,how do i fix it
 
public with sharing class saveCaseType {
     
     @AuraEnabled
     Public  static List<String>  savecasetype(string level1,string level2,string level3,string caseid){
     ERT_Case_Type__c obj=new ERT_Case_Type__c();
     Obj.Id =caseid;
     Obj.Level_1__c=level1;
     Obj.Level_2__c=level2;
     Obj.Level_3__c=level3;
     Insert obj;
     return obj;
     }
    
    
    

}

 
hey gurus,

need your help in writing test class code for below apex class
 
public with sharing class SaveRecord_Lightning{
    
	@AuraEnabled
	public static List<ERT_Case_Type> getAllrecords(){
	 
	 return [SELECT Id,Case__c,Level1__c,Level2__c,Level3__c from ERT_Case_Type];
	 }
	 
	 @AuraEnabled
	 public static ERT_Case_Type saveRecord(ERT_Case_Type recordDetail){
	   upsert recordDetail;
	   return recordDetail;
	   
	 
	 }
	
	
	}

Your help is highlyappreicated
Carolyn
Hi ,
I have an multilevel test class but problem is i dotn see 100% coverage for the tests
 Tests class is 
@isTest
public class testGetAllLevels { 

static testMethod 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();

}
    
static testMethod void testGetLevel2()
{
    Case_Type_Data__c obj = new Case_Type_Data__c();
    obj.Level_1__c = 'Test Level 1';
    obj.Level_2__c = 'Test Level 2';
    insert obj;
    List<String> s = PickListHandler.getLevel2('test');

}
    
static testMethod 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 2';
    insert obj;
    List<String> s = PickListHandler.getLevel3('test1','test2');

}
    
 
    
}

The apex class is below
public class PickListHandler {
    @AuraEnabled
    public static List<String> getLevel1(){
    List<String> tempLst1 = new List<String>();
        for(AggregateResult  ar : [select Level_1__c,COUNT(id) from Case_Type_Data__c  group by Level_1__c])
    {
        tempLst1.add(''+ar.get('Level_1__c'));
    }

    return tempLst1;
      
      
    } 
    
    @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;
      
      
    } 
   

}
here is coverage
User-added image
Your help is highly appreciated
Regards,
Carolyn​​​​​​​
I am i need to write a Spark ETL which can be executed as part of nightly batch job such that the spark job pulls the data from Azure cloud env and then populates 2 custom objects in Salesforce? Maybe 20 fields total,is it possible?
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
Hi,
I am tryin gto fetch a field value and below is the code,but i am getting below error in SForce
 
Illegal conversion from List<AggregateResult> to List<String>

here is apex code
public class PickListHandler {
    @AuraEnabled
    public static List<String> getLevel1(){
     
    
       List<AggregateResult> groupedLevel1
  = [select Level_1__c,COUNT(id) from Case_Type_Data__c  group by Level_1__c];
        
        for(AggregateResult  ar : groupedLevel1){                
           System.debug('Level Value Is' + ar.get('Level_1__c'));
        
        }
      
        return groupedLevel1;
    } 
   

}

 
Hi,

I have Case Types which  is a custom object which has these 3 fields ``` Level1 ,Level2 and Level3```  which has native dependent picklist.Current implementation is when i choose a value in ``` level 1```  then values in ``` level 2```  is reduced only those that match ``` level1```  and similarly ``` level 3```  is restricted to match level2


Now here problem is dependency in native dependent picklist limitations in no of values i can have in the ``` parent and child```  they need more than which is available 

Now to cater this problem i have 2 new custom objects ``` Case_type_data_c```  which is basically a record of all 3 fields that match up so you can have multiple ``` level1's```  records multiple ``` level 2```  records and second custom object   is ```ERT_Case_type__c```   object which matches up those          ``` Case_type_data_c```  record to the ``` case``` field in ```ERT_Case_type__c```
User-added imageUser-added imageNow i want a Salesforce lightning solution which will allow me to select say  ``` billing dispute features```  value in ``` level 1```  limits the ``` level 2's```  and when i click ``` save it```  then i need to match it up in ``` case``` field   ERT_Case_type__c

basically when i select case(which is a field in ERT_Case_type__c) then it should contain ``` level 1 ,level2 and level 3``` 
I have ERO Case Types custom object And below fields
    ```Fields:
    Case - data type - Master / Detail (Case)
    Level1
    Level2
    Level3
    Primary - checkbox
    Active - checkbox```

also another custom object named: Case Types Data to 
     ```Fields:
     Level1
     Level2
     Level3
     Primary - checkbox
     Active - checkbox```

My requirement is to build lightning component  to assign Case Type combo selected to current Case

Basically ,I Want To be able to **select 3 case types starting with Level 1, and Level 2 (based on value selected in Level 1) and Level 3(based on Level 1 and Level 2 values selected)
SO THAT I can assign this combination of Levels 1-3 to current case I am working on.**
The below is to closely replicate current functionality of Case Type (See  screenshot)
User-added image
Hi Gurus,

Our BI team can't pull in our description field from Cases because it's too long.   and we need to created a truncated version of this field for 255 characters

my question is what's the best way to do this?  on existing data and new data

Regards,
carolyn
Dear Gurus,

This is about a Apex DML exception which is troubling
23:43:49:014 EXCEPTION_THROWN [49]|System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Level 1, Case]: [Level 1, Case]

Here is apex code-->
public class PickListHandler {
    @AuraEnabled
    public static List<String> getLevel1(){
    List<String> tempLst1 = new List<String>();
        for(AggregateResult  ar : [select Level_1__c,COUNT(id) from Case_Type_Data__c  group by Level_1__c])
    {
        tempLst1.add(''+ar.get('Level_1__c'));
    }

    return tempLst1;
      
      
    } 
    
    @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 caseid){
     string strMsg='successfull';
          try{
     ERT_Case_Type__c obj=new ERT_Case_Type__c();
     Obj.Case__c =caseid;
     Obj.Level_1__c=level1;
     Obj.Level_2__c=level2;
     Obj.Level_3__c=level3;
     Insert obj;
     Return 'Successfully Inserted Levels';
     }
     
    catch(Exception ex){
            strMsg='error';
        }
     return strMsg;  
}
    
     
    
    

}

Hereis working Test class for above apex-->
@isTest
public class testGetAllLevels { 

static testMethod 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();

}
    
static testMethod 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');

}
    
static testMethod 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');

}
    
    
static testMethod 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 lightning component JS -->
({
    doInit : function(component, event, helper) {
        var action = component.get("c.getLevel1");
        action.setCallback(this, function(e) {
            if(e.getState()=='SUCCESS'){
                var result=e.getReturnValue();
                component.set("v.lstLevel1",result);
            }
        });
        $A.enqueueAction(action);
    },    
    getLvl1:function(component, event, helper){
       
        var picklist=component.find('ddLevel1');
        var picklistvalue=picklist.get('v.value');
        var action = component.get("c.getLevel2");
        //alert('called'+picklistvalue);
        action.setParams({  'strName' : picklistvalue  });//
        action.setCallback(this, function(e) {
            if(e.getState()=='SUCCESS'){
                var result=e.getReturnValue();
                component.set("v.lstLevel2",result);
            }
        });
        $A.enqueueAction(action);
        //  alert(picklistvalue);
    },
    getSelectedValue:function(component, event, helper){
        var picklist=component.find('ddLevel1');
        var picklistvalue=picklist.get('v.value');
        var picklistdep=component.find('ddLevel2');
        var picklistvaluedep2=picklistdep.get('v.value');
        var action = component.get("c.getLevel3");
       // alert(picklistvaluedep2+' called'+picklistvalue);
        action.setParams({  'strName1' : picklistvalue,
                         'strName2' : picklistvaluedep2});//
        action.setCallback(this, function(e) {
            if(e.getState()=='SUCCESS'){
                var result=e.getReturnValue();
                component.set("v.lstL3",result);
            }
        });
        $A.enqueueAction(action);
       // alert(picklistvalue+'  '+picklistvaluedep);
    },
    onConfirm:function(component, event, helper){
        var picklist=component.find('ddLevel1');
        var picklistvalue=picklist.get('v.value');
        var picklistdep=component.find('ddLevel2');
        var picklistvaluedep2=picklistdep.get('v.value');
       
        var picklistdep3=component.find('ddLevel3');
        var picklistvaluedep3=picklistdep3.get('v.value');
        var action = component.get("c.savecasetype");
        
        action.setParams({  'strName1' : picklistvalue,
                          'strName2' : picklistvaluedep2,
                          'strName3' : picklistvaluedep3,
                          'id' : component.get("v.recordId")});//
                          
        
        var toastEvent = $A.get("e.force:showToast");
       //alert('abcd');
        action.setCallback(this, function(e) {
            if(e.getState()=='SUCCESS'){
                var result=e.getReturnValue();
                // alert(result);
                if(result==='successfull'){
                    toastEvent.setParams({
                        "title": "Success!",
                        "message": "The record has been inserted  successfully."
                    });
                    toastEvent.fire();
                }else{
                    toastEvent.setParams({
                        "title": "Error",
                        "message": "The record has not been inserted  successfully."
                    });
                    toastEvent.fire();
                }
            }
        });
        $A.enqueueAction(action);
       
    }
})

Here is Apex handler -->
<aura:component controller="PickListHandler" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    <!-- Actions-->
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
    <!-- variable-->
    <aura:attribute name="lstLevel1" type="String[]" />
     <aura:attribute name="lstLevel2" type="String[]" />
      <aura:attribute name="lstL3" type="String[]" />
    <span> Level 1</span>
    <ui:inputSelect aura:id="ddLevel1" change="{!c.getLvl1}">
        <ui:inputSelectOption label="-Select-" value="true"/>        
        <aura:iteration items="{!v.lstLevel1}" var="value">          
            <ui:inputSelectOption label="{!value}" text="{!value}" />
        </aura:iteration>
    </ui:inputSelect>
    <span>Level 2</span>
    <ui:inputSelect aura:id="ddLevel2" change="{!c.getSelectedValue}">
        <ui:inputSelectOption label="-Select-" value="true"/>        
        <aura:iteration items="{!v.lstLevel2}" var="value">          
            <ui:inputSelectOption label="{!value}" text="{!value}" />
        </aura:iteration>
    </ui:inputSelect>
     <span>Level 3</span>
    <ui:inputSelect aura:id="ddLevel3" >
        <ui:inputSelectOption label="-Select-" value="true"/>        
        <aura:iteration items="{!v.lstL3}" var="value">          
            <ui:inputSelectOption label="{!value}" text="{!value}" />
        </aura:iteration>
    </ui:inputSelect>
    <lightning:button variant="brand" label="Save" onclick="{!c.onConfirm}" />
</aura:component>
Now when i run test class basically create a case and pass the id to apex class,i see no issues but issue comes only when i click 'Save',i see ""The record has not been inserted successfully."" On checking Logs i found DML exception as below
23:43:49:014 EXCEPTION_THROWN [49]|System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Level 1, Case]: [Level 1, Case]

Please note in this scenarion Each case can have multiple ERT_Case_Type__c and each ERT_Case_Type__c can have multiple Case_Type_Data__c

Please help in finding  resolution.

Thanks in Advance
Carolyn
 
i am having 90% code coverage because atch block is not covered,can anyone help in writing code for catch block as well

Apex code -->
public class PickListHandler {
    @AuraEnabled
    public static List<String> getLevel1(){
    List<String> tempLst1 = new List<String>();
        for(AggregateResult  ar : [select Level_1__c,COUNT(id) from Case_Type_Data__c  group by Level_1__c])
    {
        tempLst1.add(''+ar.get('Level_1__c'));
    }

    return tempLst1;
      
      
    } 
    
    @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 caseid){
     string strMsg='successfull';
          try{
     ERT_Case_Type__c obj=new ERT_Case_Type__c();
     Obj.Case__c =caseid;
     Obj.Level_1__c=level1;
     Obj.Level_2__c=level2;
     Obj.Level_3__c=level3;
     Insert obj;
     Return 'Successfully Inserted Levels';
     }
     
    catch(Exception ex){
            strMsg='error';
        }
     return strMsg;  
}

}

Test class code -->
@isTest
public class testGetAllLevels { 

static testMethod 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();

}
    
static testMethod 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');

}
    
static testMethod 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');

}
    
    
static testMethod 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();
    }
    
 
    
}

Thanks in advance
Carolyn
Hi Team,

appreciate your help,please help me in completing the test class for below
 
public with sharing class saveCaseType {
     
     @AuraEnabled
     Public  static ERT_Case_Type__c  savecasetype(string level1,string level2,string level3,string caseid){
     ERT_Case_Type__c obj=new ERT_Case_Type__c();
     Obj.Id =caseid;
     Obj.Level_1__c=level1;
     Obj.Level_2__c=level2;
     Obj.Level_3__c=level3;
     Insert obj;
     return obj;
     }
    
    
    

}

Thanks in Advance
Carolyn​​​​​​​
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