You need to sign in to do that
Don't have an account?
Jaanu
Test Coverage for Apex Class ?
Pls see the apex class below ..there If cluase in bold .. I have 5 other if caluses with different conditions like create, next, save, sample etc. Somehow I am not able to get code coverage for this. If someone can give this, I will be able to replicate the same test code for other if clauses as well... pls help me with the test coverage code ....thanks.
@AuraEnabled
public static List<item> getEndos(string recordId,string bundle){
Prod_Cre__mdt prodCre=[select Bundle_Draft_Status__c,Bundle_Return_Status__c,Client_Plan_Record_Type__c from Prod_Cre__mdt];
List<String> status=new List<String>{prodCre.Bundle_Draft_Status__c,prodCre.Bundle_Return_Status__c};
opportunity oppId=[select accountid,Plan_Due_Date__c from opportunity where id=:recordId];
List<Endo_Map__c> EndoMap=[SELECT Id,New_Endo__c, New_Endo_Code__c, New_Endo_Name__c,Old_Endo__c FROM Endo_Map__c WHERE Replacement_Date__c <=:oppId.Plan_Due_Date__c];
List<item>items =new List<item>();
if(bundle=='Create'){
List<Product_Endo__c> prodEndos=[SELECT Endo_Code__c,Endo__c,Endo_Name__c,Id,Pilot__c,Product__c FROM Product_Endo__c WHERE Product__c IN (SELECT Plan__c FROM Client_Plan__c where Account__c=:oppid.Accountid and RecordType.DeveloperName =:prodCre.Client_Plan_Record_Type__c)];
for(Product_Endo__c prod: prodEndos){
if(EndoMap.size()>0){
for(Endo_Map__c endMap:EndoMap){
if(prod.Endo__c==endMap.Old_Endo__c){
item oppitem = new item(prod.Endo_Name__c, String.valueOf(prod.Id), prod.Endo_Code__c, prod.Pilot__c, true);
items.add(oppitem);
}else{
item oppitem = new item(prod.Endo_Name__c, String.valueOf(prod.Id), prod.Endo_Code__c, prod.Pilot__c, null);
items.add(oppitem);
}
}
}else{
item oppitem = new item(prod.Endo_Name__c, String.valueOf(prod.Id), prod.Endo_Code__c, prod.Pilot__c, null);
items.add(oppitem);
}
}
}
return items;
}
@AuraEnabled
public static List<item> getEndos(string recordId,string bundle){
Prod_Cre__mdt prodCre=[select Bundle_Draft_Status__c,Bundle_Return_Status__c,Client_Plan_Record_Type__c from Prod_Cre__mdt];
List<String> status=new List<String>{prodCre.Bundle_Draft_Status__c,prodCre.Bundle_Return_Status__c};
opportunity oppId=[select accountid,Plan_Due_Date__c from opportunity where id=:recordId];
List<Endo_Map__c> EndoMap=[SELECT Id,New_Endo__c, New_Endo_Code__c, New_Endo_Name__c,Old_Endo__c FROM Endo_Map__c WHERE Replacement_Date__c <=:oppId.Plan_Due_Date__c];
List<item>items =new List<item>();
if(bundle=='Create'){
List<Product_Endo__c> prodEndos=[SELECT Endo_Code__c,Endo__c,Endo_Name__c,Id,Pilot__c,Product__c FROM Product_Endo__c WHERE Product__c IN (SELECT Plan__c FROM Client_Plan__c where Account__c=:oppid.Accountid and RecordType.DeveloperName =:prodCre.Client_Plan_Record_Type__c)];
for(Product_Endo__c prod: prodEndos){
if(EndoMap.size()>0){
for(Endo_Map__c endMap:EndoMap){
if(prod.Endo__c==endMap.Old_Endo__c){
item oppitem = new item(prod.Endo_Name__c, String.valueOf(prod.Id), prod.Endo_Code__c, prod.Pilot__c, true);
items.add(oppitem);
}else{
item oppitem = new item(prod.Endo_Name__c, String.valueOf(prod.Id), prod.Endo_Code__c, prod.Pilot__c, null);
items.add(oppitem);
}
}
}else{
item oppitem = new item(prod.Endo_Name__c, String.valueOf(prod.Id), prod.Endo_Code__c, prod.Pilot__c, null);
items.add(oppitem);
}
}
}
return items;
}
Boss Coffee
Do you have a current test class you're using? In order to cover the bolded lines, you'll need to insert test records for Product_Endo__c before calling the method with the appropriate parameters.