You need to sign in to do that
Don't have an account?
Allen2
written a test class for the following apex class. Not able to total coverage of apex class. I m not getting what is wrong. Please could anyone help me out to solve this.....
APEX CLASS
trigger updatePtCDetails on OtB__c (after update)
{
List<id> caseIds = new List<id>();
List<id> PCaseids = new List<id>();
List<case> prntchildlist = new List<case>();
List<case> updcaselist=new List<case>();
Set<String> gbS = SMCUtils.getSOrgs('G P');
if(trigger.isAfter && trigger.isUpdate)
{
for(OtB__c B : trigger.new)
{
if(B.Result__c == 'Success' && B.Dt_Issued__c != null)
caseIds.add(B.Case__c);
}
system.debug('case ids from B -->'+caseIds);
if(!caseIds.isEmpty()){
for(Case cs :[select id, PtId, SX_Is_Pt_Case__c from case where id in :caseIds AND Reasons__c = 'System Generated' AND S_OG__c in :gbS]){
if(cs.SX_Is_Pt_Case__c){
PCaseids.add(cs.id);
}else
{
if(cs.prntId!=null){
PCaseids.add(cs.PtId);
}else
{
PCaseids.add(cs.id);
}
}
}
}
system.debug('parent ids list -->'+PCaseids);
if(!PCaseids.isEmpty()){
prntchildlist=[select id,Reasons__c,C_Status__c,(select id,C_Completed_On__c from Cases) from case where id in :PCaseids];
}
system.debug('parent child list -->'+prntchildlist);
for(Case parent : prntchildlist)
{
Boolean isDateNull=false;
for(Case child : parent.cases)
{
if(child.C_Completed_On__c==null)
{
isDateNull=true;
break;
}
}
if(isDateNull==false)
{
parent.C_Status__c='Process Complete';
updcaselist.add(parent);
}
}
if(!updcaselist.isEmpty())
{
system.debug('inside update for case list in B-->'+updcaselist);
update updcaselist;
}
}
}
TEST CLASS
@isTest
public class updatePtCDetailsTest
{
static testMethod void TestMethod1()
{
Test.startTest();
List<OtB__c> otlist =[select id,Case__c,Result__c,Dt_Issued__c from OtB__c limit 1];
if(!ologlist.isEmpty())
{
otlist[0].Dt_Issued__c=system.today();
otlist[0].Result__c='Success';
update otlist;
}
Test.stopTest();
}
static testMethod void TestMethod()
{
Test.startTest();
Set<String> gbS = SMCUtils.getSOrgs('G P');
List<Case> cs=[select id, PtId, SX_Is_Pt_Case__c,CCDetails__c from case where Reasons__c = 'System Generated' AND S_OG__c in :gbS AND CCDetails__c!=null
limit 1];
if(!cs.isEmpty())
{
List<OtB__c> otlist =[select id,Case__c,Result__c,Dt_Issued__c from OtB__c
where Case__c=:cs[0].CCDetails__c limit 1];
if(!otlist.isEmpty())
{
otlist[0].Dt_Issued__c = null;
otlist[0].Result__c='Success';
update otlist;
}
}
Test.stopTest();
}
}
The bold and underlined part is not able to cover. please help me out for this.. urgent...
trigger updatePtCDetails on OtB__c (after update)
{
List<id> caseIds = new List<id>();
List<id> PCaseids = new List<id>();
List<case> prntchildlist = new List<case>();
List<case> updcaselist=new List<case>();
Set<String> gbS = SMCUtils.getSOrgs('G P');
if(trigger.isAfter && trigger.isUpdate)
{
for(OtB__c B : trigger.new)
{
if(B.Result__c == 'Success' && B.Dt_Issued__c != null)
caseIds.add(B.Case__c);
}
system.debug('case ids from B -->'+caseIds);
if(!caseIds.isEmpty()){
for(Case cs :[select id, PtId, SX_Is_Pt_Case__c from case where id in :caseIds AND Reasons__c = 'System Generated' AND S_OG__c in :gbS]){
if(cs.SX_Is_Pt_Case__c){
PCaseids.add(cs.id);
}else
{
if(cs.prntId!=null){
PCaseids.add(cs.PtId);
}else
{
PCaseids.add(cs.id);
}
}
}
}
system.debug('parent ids list -->'+PCaseids);
if(!PCaseids.isEmpty()){
prntchildlist=[select id,Reasons__c,C_Status__c,(select id,C_Completed_On__c from Cases) from case where id in :PCaseids];
}
system.debug('parent child list -->'+prntchildlist);
for(Case parent : prntchildlist)
{
Boolean isDateNull=false;
for(Case child : parent.cases)
{
if(child.C_Completed_On__c==null)
{
isDateNull=true;
break;
}
}
if(isDateNull==false)
{
parent.C_Status__c='Process Complete';
updcaselist.add(parent);
}
}
if(!updcaselist.isEmpty())
{
system.debug('inside update for case list in B-->'+updcaselist);
update updcaselist;
}
}
}
TEST CLASS
@isTest
public class updatePtCDetailsTest
{
static testMethod void TestMethod1()
{
Test.startTest();
List<OtB__c> otlist =[select id,Case__c,Result__c,Dt_Issued__c from OtB__c limit 1];
if(!ologlist.isEmpty())
{
otlist[0].Dt_Issued__c=system.today();
otlist[0].Result__c='Success';
update otlist;
}
Test.stopTest();
}
static testMethod void TestMethod()
{
Test.startTest();
Set<String> gbS = SMCUtils.getSOrgs('G P');
List<Case> cs=[select id, PtId, SX_Is_Pt_Case__c,CCDetails__c from case where Reasons__c = 'System Generated' AND S_OG__c in :gbS AND CCDetails__c!=null
limit 1];
if(!cs.isEmpty())
{
List<OtB__c> otlist =[select id,Case__c,Result__c,Dt_Issued__c from OtB__c
where Case__c=:cs[0].CCDetails__c limit 1];
if(!otlist.isEmpty())
{
otlist[0].Dt_Issued__c = null;
otlist[0].Result__c='Success';
update otlist;
}
}
Test.stopTest();
}
}
The bold and underlined part is not able to cover. please help me out for this.. urgent...
Could you please check your test class, what value you are getting in line 7
And you have not even created the dummy/sample data for your test class.
First of all create some dummy/sample data and fullfill the criteria based on the class. Below are the link for reference
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_qs_test.htm
https://trailhead.salesforce.com/modules/apex_testing/units/apex_testing_intro
Thanks & Regards,
Ganesh Hembram
Only the testmethod1 is covering all the code testmethod is not covering anything. Just help me how to cover if else part in this...
Could you please try the below code snippet for testmethod once and let me know..
Thanks & Regards,
Ganesh Hembram
Getting this error in "IN operator must be used with an iterable expression" while creating "list<case> " . we can't use Id In: oTBList[0].case__c.
M not able to solve this.
Set , Id variable not exist for line 4, Case__c variable not exist for line 14, Id variable not exist for line 17.