function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
GurunathGurunath 

Test Coverage Help

Voucher is parent object and treasure_chest_application__c is my child object ,the issue is i could not able to cover the code for this in test class.......can please help to me  in writing test class for this............

 

for(Treasure_Chest_Application__c TCA :queryvouchers.Treasure_Chest_Applications__r){
if(TCA.Date_of_the_Event__c != null ){

if((date.today().month() - TCA.Date_of_the_Event__c.month() <= 1) && (date.today().year() == TCA.Date_of_the_Event__c.year())){

RelatedVoucher.add(queryvouchers);
}
}
}
}
for(Voucher__c CalVouchers : RelatedVoucher ){
TotalRaffles = 0 ;
TotalEvents = 0 ;
NumberEventsBenefiting = 0;

for(Treasure_Chest_Application__c TCA1 :CalVouchers.Treasure_Chest_Applications__r){
if(TCA1.Date_of_the_Event__c != null && TCA1.Amount_Raised_for_Voucher__c != null && TCA1.Amount_Raised_for_Event__c != null ){

if((date.today().month() - TCA1.Date_of_the_Event__c.month() <= 1) && (date.today().year() == TCA1.Date_of_the_Event__c.year())){


// NumberEventsBenefiting += Integer.valueOf(TCA1.get('expr0'));
NumberEventsBenefiting++;
TotalRaffles += Integer.valueOf(TCA1.Amount_Raised_for_Voucher__c);
TotalEvents += Integer.valueOf(TCA1.Amount_Raised_for_Event__c);
system.debug('&&&&&&&&&&&&&&&&&&&&&&&&&&&'+ TotalRaffles);
}
}
}
}

testrest97testrest97

Just create test data which matches the conditions(so that it enters the loops) and call the method. Pasting the entire method/class might be more helpful to see how to reach this part of code

GurunathGurunath

thanks for you response ........i have done it.