You need to sign in to do that
Don't have an account?
SFDC12
wrapperclass account related contacts
Hi everyone,can someone help how to write testclass for the below code..
Thanks in Advance.
public class Displayrelatedlists {
//1.list of wrapperclass
public list<AccountContactWrapper> lstAccountContactWrapper { get; set; }
public list<AccountContactWrapper> lstSelectedAccountContactWrapper { get; set; }
//list for selecting the account records
public list<account> selectedAccounts{get;set;}
public Displayrelatedlists () {
//Allocating the memory for the list
lstSelectedAccountContactWrapper = new list<AccountContactWrapper>();
if(lstAccountContactWrapper == null) {
//allocate memory for the wrapperlist
lstAccountContactWrapper = new list<AccountContactWrapper>();
for(account a:[select id,name,phone,(select id,name from contacts)from account limit 10]) {
lstAccountContactWrapper.add(new AccountContactWrapper(a));
}
}
}
public void ProcessSelected() {
lstSelectedAccountContactWrapper =new list<AccountContactWrapper>();
selectedAccounts =new list<Account>();
for(AccountContactWrapper wrapobj:lstAccountContactWrapper){
if(wrapobj.isSelected==true) {
selectedAccounts.add(wrapobj.acc);
}
}
for(Account acc:[select id,name,phone,(select id,name from contacts) from account where id in:selectedAccounts]) {
lstSelectedAccountContactWrapper.add(new AccountContactWrapper(acc));
}
}
public class AccountContactWrapper {
public Account acc {get;set;}
public boolean isSelected {get;set;}
public AccountContactWrapper(account a) {
acc = a;
isselected=false;
}
}
}
Thanks in Advance.
public class Displayrelatedlists {
//1.list of wrapperclass
public list<AccountContactWrapper> lstAccountContactWrapper { get; set; }
public list<AccountContactWrapper> lstSelectedAccountContactWrapper { get; set; }
//list for selecting the account records
public list<account> selectedAccounts{get;set;}
public Displayrelatedlists () {
//Allocating the memory for the list
lstSelectedAccountContactWrapper = new list<AccountContactWrapper>();
if(lstAccountContactWrapper == null) {
//allocate memory for the wrapperlist
lstAccountContactWrapper = new list<AccountContactWrapper>();
for(account a:[select id,name,phone,(select id,name from contacts)from account limit 10]) {
lstAccountContactWrapper.add(new AccountContactWrapper(a));
}
}
}
public void ProcessSelected() {
lstSelectedAccountContactWrapper =new list<AccountContactWrapper>();
selectedAccounts =new list<Account>();
for(AccountContactWrapper wrapobj:lstAccountContactWrapper){
if(wrapobj.isSelected==true) {
selectedAccounts.add(wrapobj.acc);
}
}
for(Account acc:[select id,name,phone,(select id,name from contacts) from account where id in:selectedAccounts]) {
lstSelectedAccountContactWrapper.add(new AccountContactWrapper(acc));
}
}
public class AccountContactWrapper {
public Account acc {get;set;}
public boolean isSelected {get;set;}
public AccountContactWrapper(account a) {
acc = a;
isselected=false;
}
}
}
Please try the below test class:
Thanks,
Maharajan.C
All Answers
Please try the below test class:
Thanks,
Maharajan.C