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
SFDC@ChennaiSFDC@Chennai 

Test class coverage in apex

List < Report__c > frList = new List < Report__c > ();

How sholud i use the code for covering above line in apex test class? can any one have idea!!
SarfarajSarfaraj
Please post your full code.
SFDC@ChennaiSFDC@Chennai
Public class MyClass{
public MyClass (ApexPages.StandardController stdController) {}
public PageReference save() {

List < Report__c > foreRevRep = [SELECT Amount__c, Month__c, opp_id__c FROM Report__c WHERE opp_id__c = : this.oppId];
if (foreRevRep != null && foreRevRep.size() > 0) {
 
List < Report__c > frList = new List < Report__c > ();
if (opp.Select_Month_Division__c == '6' || opp.Select_Month_Division__c == '12' || opp.Select_Month_Division__c == '18' || opp.Select_Month_Division__c == '24' || opp.Select_Month_Division__c == '30' || opp.Select_Month_Division__c == '36') {
Report__c frr = new Report__c();
frr.opp_id__c = opp.Id;
if (this.amount1 != null) {
frr. Month__c = this.month1;
frr. Amount__c = this.amount1;
frr.Flag__c = 1;
frList.add(frr);
}
}
}
}}

@isTest
Public class MyTestClass{
Static testMethod void testMethod1(){
MyClass mc = new MyClass(new ApexPages.StandardController(o));
mc.save();
}
}
Ravikant kediaRavikant kedia
This List of report  will automatic cover  but i think problem in your if condition first check that your if condition is exicute or not.
SFDC@ChennaiSFDC@Chennai
Ravikant kedia,

It is working fine with all the conditons and functionality, the only problem is test class wouldn't cover up those.
SarfarajSarfaraj
Hi

Both your controller and Test class seems to be incomplete.
1. I assume that this.oppId has valid not null value,
List < Report__c > foreRevRep = [SELECT Amount__c, Month__c, opp_id__c FROM Report__c WHERE opp_id__c = : this.oppId];
2. I assume that o has proper not null value in your test class,
MyClass mc = new MyClass(new ApexPages.StandardController(o));
Create some Report__c records in your test class with proper opp_id__c before calling mc.save(). 
In case this does not help you, please post your full code.

Regards
Akram
SFDC@ChennaiSFDC@Chennai
Hi Ravikant kedia,

Your correct i removed if condition  and checked the code coverage incresed ,but i have to use if condition can you please suggest some ideas .

Thanks in advance
Ravikant kediaRavikant kedia
You have to insert at least one record for Report__c object beforce to call save method and id should be similer to your condition .(Keep in mind id should not hardcoded).