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;
Attribution to: PavanFoxPro
Possible Suggestion/Solution #1
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
- create a new Account record
- insert it
- then continue from the line: "accToDel = [SELECT Name,Id,Phone, Description FROM Account];"
Attribution to: RohanC
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/33753