You need to sign in to do that
Don't have an account?
sfdc dev 2264
Dates if condition coverage in test class help needed
Hi,
I have a controller for which i have written a test class which covers only 50%, I am not able to cover the following lines for which i need help on it
//
if(firstcontract.Contract_Start_Date__c<contractObj.Contract_Start_Date__c && firstcontract.Contract_End_Date__c<contractObj.Contract_End_Date__c ){
if(firstcontract.Contract_End_Date__c>=contractObj.Contract_Start_Date__c){
firstcontract.Contract_End_Date__c=contractObj.Contract_Start_Date__c.addDays(-1);
update firstcontract;//put the list and update
}
}
else{
system.debug('elsesection');
if(contractObj.Contract_End_Date__c>=firstcontract.Contract_Start_Date__c){
contractObj.Contract_End_Date__c=firstcontract.Contract_Start_Date__c.addDays(-1);
update contractObj;// put the list and update
}
//
if(idVsContractmap.containsKey(controbj.Account__r.Id)) {
List<Contract__c> contrAccList = idVsContractmap.get(controbj.Account__r.Id);
contrAccList.add(controbj);
idVsContractmap.put(controbj.Account__c, contrAccList);
} else {
idVsContractmap.put(controbj.Account__c, new List<Contract__c> { controbj });
}
//
Kindly help me pls
Thanks in advance
I have a controller for which i have written a test class which covers only 50%, I am not able to cover the following lines for which i need help on it
//
if(firstcontract.Contract_Start_Date__c<contractObj.Contract_Start_Date__c && firstcontract.Contract_End_Date__c<contractObj.Contract_End_Date__c ){
if(firstcontract.Contract_End_Date__c>=contractObj.Contract_Start_Date__c){
firstcontract.Contract_End_Date__c=contractObj.Contract_Start_Date__c.addDays(-1);
update firstcontract;//put the list and update
}
}
else{
system.debug('elsesection');
if(contractObj.Contract_End_Date__c>=firstcontract.Contract_Start_Date__c){
contractObj.Contract_End_Date__c=firstcontract.Contract_Start_Date__c.addDays(-1);
update contractObj;// put the list and update
}
//
if(idVsContractmap.containsKey(controbj.Account__r.Id)) {
List<Contract__c> contrAccList = idVsContractmap.get(controbj.Account__r.Id);
contrAccList.add(controbj);
idVsContractmap.put(controbj.Account__c, contrAccList);
} else {
idVsContractmap.put(controbj.Account__c, new List<Contract__c> { controbj });
}
//
Kindly help me pls
Thanks in advance
Could you please post your test class? You have to create a record of contarctObjs where start date should in between firstContacts start date and end date then you can cover
Thanks,
Kirti Rathod
Please find my test class and apex class for your kind reference
Please check and let me know .
Thanks,
Kirti Rathod
Try to use System.debugs in controller and find where the condition is not matched.