You need to sign in to do that
Don't have an account?
yarram
Urgent: not able to do code coverage for "FOR loop 'IF statement'"
Hi all,
i have two custon objects (Case_Application__c(master) and Education_Application_Detail__c(detail)) these both has master-detail relation ship. here what i have to do --- if master object record doesn't have the child records then i have to create child(detail) record with master object record data automatically. i have done this but i am not able to do the code coverage for this logic. below is my class code how can i write the test class for this atleast 80% code coverage. Please help me on this.
public with sharing class RecordTypeCtrl {
public ID eadRecordTypeId {get;set;}
List<Case_Application__c> caList;
public RecordTypeCtrl(){
eadRecordTypeId = Schema.SObjectType.Case_Application__c.RecordTypeInfosByName.get('Education').RecordTypeId;
if(eadRecordTypeId!=null){
eadDetails();
}
}
public void eadDetails(){
caList=[select id,name,recordtype.name,Award__c,
(select id,name,Case_Application__c from Education_Application_Details__r),Case_Application_Status__c,Case_File__c,
Course_Type__c,Details_of_Exceptional_Need__c,Exceptional_Needs_Cost__c,
Purpose__c,Sign_Language_Interpreting_Cost__c from Case_Application__c
where RecordTypeId=:eadRecordTypeId];
List<Education_Application_Detail__c> eadList=new List<Education_Application_Detail__c>();
for(Case_Application__c ca: caList){
if(ca.Education_Application_Details__r.size()==0){ ----------//from here not cover
Education_Application_Detail__c ead=new Education_Application_Detail__c();
ead.Case_Application__c=ca.Id;
ead.Course_Type__c=ca.Course_Type__c;
ead.Award__c=ca.Award__c;
eadList.add(ead);
}-------------/// Upto here not cover
}
if(eadList.size()>0){
insert eadList;
}
}
}
please help me on this
Thanks,
Yarram.
i have two custon objects (Case_Application__c(master) and Education_Application_Detail__c(detail)) these both has master-detail relation ship. here what i have to do --- if master object record doesn't have the child records then i have to create child(detail) record with master object record data automatically. i have done this but i am not able to do the code coverage for this logic. below is my class code how can i write the test class for this atleast 80% code coverage. Please help me on this.
public with sharing class RecordTypeCtrl {
public ID eadRecordTypeId {get;set;}
List<Case_Application__c> caList;
public RecordTypeCtrl(){
eadRecordTypeId = Schema.SObjectType.Case_Application__c.RecordTypeInfosByName.get('Education').RecordTypeId;
if(eadRecordTypeId!=null){
eadDetails();
}
}
public void eadDetails(){
caList=[select id,name,recordtype.name,Award__c,
(select id,name,Case_Application__c from Education_Application_Details__r),Case_Application_Status__c,Case_File__c,
Course_Type__c,Details_of_Exceptional_Need__c,Exceptional_Needs_Cost__c,
Purpose__c,Sign_Language_Interpreting_Cost__c from Case_Application__c
where RecordTypeId=:eadRecordTypeId];
List<Education_Application_Detail__c> eadList=new List<Education_Application_Detail__c>();
for(Case_Application__c ca: caList){
if(ca.Education_Application_Details__r.size()==0){ ----------//from here not cover
Education_Application_Detail__c ead=new Education_Application_Detail__c();
ead.Case_Application__c=ca.Id;
ead.Course_Type__c=ca.Course_Type__c;
ead.Award__c=ca.Award__c;
eadList.add(ead);
}-------------/// Upto here not cover
}
if(eadList.size()>0){
insert eadList;
}
}
}
please help me on this
Thanks,
Yarram.
Is possible to post your test code ? I will try to modify that .
Make sure that you are populating your test data for below objects.
1. Case_Application__c with Education record type.
2. Education_Application_Details__c
Let us know if it helps you.
Can you please tell me the mandatory fields in Education_Application_Detail__c to insert record.
thanks for your reply and
Case_Application__c field is mandatory on this object. please tell me where i have to do the changes in my test class.
Thanks,
Yarram.
Please check below code
Alos you need to make the changes to your class .
@TestVisible List<Case_Application__c> caList;
Please check again below code .
I think it will help you .