+ Start a Discussion
Linga_RaminLinga_Ramin 

Unable to cover below for loop(last 2lines) in test class.Can anyone?


String strAccount ;
String StrVersant;
String accQuery = 'Select Id,Name from Account where Id =:AccountId and Id IN(Select Account__c from Pd_Mod__c where Plng_session__r.Name=:strVersant) ORDER BY Name LIMIT 15000';
            accountList= Database.query(accQuery);
            if(accountList!=null && accountList.size()>0){
               for(Account accObj:accountList){
                  strAccount = accObj.name;
               }
            }
VamsiVamsi
Hi PM Chowdary,

As you specified the below if conditon. Please make sure you create test data for accounts and Pd_Mod__c in test class ..and add a debug log for "accountList" to see it contains data while you run the test class as it is required to cover the lines you specified 

 if(accountList!=null && accountList.size()>0){


Hope this as helps ... Please mark as best answer if the above helps ..!!
Deepali KulshresthaDeepali Kulshrestha
Hi,

It looks like you are getting "accountList" empty in apex class while running test class. Please make sure you have inserted the accounts in Test class or check for any exception in the debug logs.
 
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha