You need to sign in to do that
Don't have an account?
Sahil Yadav
Apex Test Class Code Coverage
Hello Folks ,
I will be working on one scenario where a case is been get created from one screen flow where there is one multiselect picklist fields with the label state where end user can select multiple state value during the case creation . Now I need to create a child cases of the cases which is been created bu the screen flow.
So ideally one parent case is get created through screen flow where suppose state an end user selected is AK, AL, CZ then the three child cases must be get created because 3 states is been selected AK, AL, CZ
So Parent Case get created from screen flow and passing the case id from flow to apex class to create a no of child cases depend upon the number of state field values.
Now how may i proceed futher not geting an idea please let me know if any comments
How should i wrote a test class for this scenarios?
I will be working on one scenario where a case is been get created from one screen flow where there is one multiselect picklist fields with the label state where end user can select multiple state value during the case creation . Now I need to create a child cases of the cases which is been created bu the screen flow.
So ideally one parent case is get created through screen flow where suppose state an end user selected is AK, AL, CZ then the three child cases must be get created because 3 states is been selected AK, AL, CZ
So Parent Case get created from screen flow and passing the case id from flow to apex class to create a no of child cases depend upon the number of state field values.
Code for creating a child Case public class createChildCase { @InvocableMethod public static void createChild(List<Id> caseIds){ System.debug('createChildCaseInvoked'); Case parentCase = [Select id, subject , description, DDI_States_Of_Interests__c from Case where id = : caseIds[0]]; List<String> States = parentCase.DDI_States_Of_Interests__c.split(';'); System.debug('States Size' +States.size() ); List<Case> childCase = new List<Case>(); for(integer i = 0; i< States.size(); i++ ){ String state = States[i]; System.debug('State :' +state); Case caseAL = new Case(); System.debug('@@'); caseAL.Subject = 'Sub Case for Different States'; System.debug('@@'); caseAL.ParentId = parentCase.Id; System.debug('@@'); caseAL.RecordTypeId = '01223000000NZDEAA4'; System.debug('@@'); caseAl.DDI_States_Of_Interests__c = state; //insert caseAK; childCase.add(caseAL); } System.debug('@@' +childCase.size()); //System.debug('@@' +caseAL.Id); insert childCase; //return childCase; } }
Test Class @isTest public class createChildCaseTest { @isTest public static void createChild(){ Case cases = new Case(); cases.CaseEmail__c= 'yadavsahil46623@gmail.com'; cases.MultiSelect_State__c = 'AZ, AR, CA'; cases.Subject = 'Case is been getting created'; insert cases; List<Case> caseList = [Select Id, subject,CaseEmail__c, MultiSelect_State__c from Case where id =: cases.Id ]; System.assertEquals('yadavsahil46623@gmail.com',cases.CaseEmail__c ); } }
Now how may i proceed futher not geting an idea please let me know if any comments
How should i wrote a test class for this scenarios?
TRy Below Class 100 % Coverage Please Mark It As Best Answer If It Helps
Thank You!
All Answers
TRy Below Class 100 % Coverage Please Mark It As Best Answer If It Helps
Thank You!
Please use below code:-
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
you can check my code and compare with your and execute my code in your test class.
As per my analysis in main class you are spliting using ; and in test class you are using ,
cases.DDI_States_Of_Interests__c = 'AZ, AR, CA';
if you see in my code i am usign ; instead of ,
Don't need to write SOQL
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh