0
public class deleterecords1{  
   public List<sObjectWrapper> wrappers{get;set;}  
   public deleterecords1(){  
     wrappers = getData();  
   }  
   public void deleteRecords(){  
     List<Account> accToDel = new List<Account>();  
     for(sObjectWrapper wrap : wrappers){  
       if(wrap.isSelected){  
         accToDel.add(wrap.myAccount);  
       }  
     }  
     delete accToDel;  
     wrappers = getData();  
   }  
   public List<sObjectWrapper> getData(){  
     List<sObjectWrapper> wrappers = new List<sObjectWrapper>();  
     for(Account acc : [SELECT Name,Id,Phone, Description FROM Account]){  
       wrappers.add(new sObjectWrapper(acc,false));  
     }  
     return wrappers;  
   }  
   public class sObjectWrapper{  
    public boolean isSelected{get;set;}  
    public Account myAccount{get;set;}  
    public sObjectWrapper(Account myAccount,Boolean isSelected){  
     this.myAccount = myAccount;  
     this.isSelected = isSelected;  
    }  
   }  
 }

This is my test class

@isTest

Public class deleterecordsTest{
     public static testMethod void deleteTest(){
        List<Account> accToDel = new List<Account>();
        accToDel = [SELECT Name,Id,Phone, Description FROM Account];
        delete accToDel;
        deleterecords1 d1 = new deleterecords1();
        d1.deleteRecords();
        d1.getData();


    }
}

code coverage is 60%

the code coverage is not coming for below code. how can i increase code coverage for this.

  if(wrap.isSelected){  
         accToDel.add(wrap.myAccount);  


       wrappers.add(new sObjectWrapper(acc,false));  


t;}  
    public Account myAccount{get;set;}  
    public sObjectWrapper(Account myAccount,Boolean isSelected){  
     this.myAccount = myAccount;  
     this.isSelected = isSelected;  

1 Answer 1

3

Are you sure your test class is returning any rows at all? I would assume your initial SELECT query will return 0 rows.

If you must use existing records in your test class, change the initial notation to: @isTest(SeeAllData=true)

ALthough, the recommended method would be to

  1. create a new Account record
  2. insert it
  3. then continue from the line: "accToDel = [SELECT Name,Id,Phone, Description FROM Account];"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .