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 for list index

Hi, This following code is in my apex class.
In my test clas i can cover up List and followed by if condition, the bold part is not covering up. Please share me if any one have idea.

List < Forecast_Revenue_Report__c > getFlagVal = [SELECT Flag__c FROM Forecast_Revenue_Report__c WHERE Forecast_Month__c = : this.month1];
if(!getFlagVal.isEmpty()){

     this.flag = getFlagVal[0].Flag__c;

Thanks.
Best Answer chosen by SFDC@Chennai
bob_buzzardbob_buzzard
This means that your query doesn't return any rows.  It sounds like you should be inserting some forecasting test data so that the getFlagVal list isn't empty.

All Answers

bob_buzzardbob_buzzard
This means that your query doesn't return any rows.  It sounds like you should be inserting some forecasting test data so that the getFlagVal list isn't empty.
This was selected as the best answer
SFDC@ChennaiSFDC@Chennai
Yes Bob, I did insert test data before use cal the list like below

Forecast_Revenue_Report__c f = new Forecast_Revenue_Report__c(opp_id__c = '007Z000000YhjjjA', Forecast_Month__c = 'Jan_2014', Forecast_Amount__c = 500, Flag__c = 36);
        insert f;

U JayU Jay
Can you debug this.month1 ????

I think it is not matchong with 'Jan_2014'... can you check please???
Ravi NarayananRavi Narayanan
where forecastmonth = this.month1. 


Can you please tell what is the value of this.month1? is it the current month ?  if so, then your record should be inserted with the value of Forecast_Month__c as Oct_2014 ..  then your query will return values 
SFDC@ChennaiSFDC@Chennai
Not current month the value will be dynamicaly chaning based on the some cloing date,
U JayU Jay
Is this.month1 = Jan_2014???
other vice error will have no coverage...