You need to sign in to do that
Don't have an account?
Naresh.soft12
i want test class for my code
Hi,
can one help me .i want test class for my code
public class WrapperClassController
{
public List<AccountWrapper> accWrapList{get; set;}
String queryString = 'Select Name, Type, BillingCity, BillingState, BillingCountry from Account order by Name';
public WrapperClassController()
{
accWrapList = new List<AccountWrapper>();
for(Account iter :Database.query(queryString))
{
accWrapList.add(new AccountWrapper(iter.Name,iter.Type,iter.BillingCity,iter.BillingState,iter.BillingCountry));
}
for(Contact iter :[SELECT LastName FROM Contact LIMIT 5])
{
accWrapList.add(new AccountWrapper(iter.LastName,null,null,null,null));
}
}
public PageReference ProceedAction()
{
for(AccountWrapper iter :accWrapList)
{
if(iter.isSelected)
{
//Do necessary customization
}
}
return null;
}
public class AccountWrapper
{
public String accName{get; set;}
public String accType{get; set;}
public String accCity{get; set;}
public String accState{get; set;}
public String accCtry{get; set;}
public Boolean isSelected{get; set;}
public String accRecId{get; set;}
public AccountWrapper(String accName, String accType, String accCity, String accState, String accCtry)
{
this.accName = accName;
this.accType = accType;
this.accCity = accCity;
this.accState = accState;
this.accCtry = accCtry;
this.accRecId = accRecId;
isSelected = false;
}
}
}
can one help me .i want test class for my code
public class WrapperClassController
{
public List<AccountWrapper> accWrapList{get; set;}
String queryString = 'Select Name, Type, BillingCity, BillingState, BillingCountry from Account order by Name';
public WrapperClassController()
{
accWrapList = new List<AccountWrapper>();
for(Account iter :Database.query(queryString))
{
accWrapList.add(new AccountWrapper(iter.Name,iter.Type,iter.BillingCity,iter.BillingState,iter.BillingCountry));
}
for(Contact iter :[SELECT LastName FROM Contact LIMIT 5])
{
accWrapList.add(new AccountWrapper(iter.LastName,null,null,null,null));
}
}
public PageReference ProceedAction()
{
for(AccountWrapper iter :accWrapList)
{
if(iter.isSelected)
{
//Do necessary customization
}
}
return null;
}
public class AccountWrapper
{
public String accName{get; set;}
public String accType{get; set;}
public String accCity{get; set;}
public String accState{get; set;}
public String accCtry{get; set;}
public Boolean isSelected{get; set;}
public String accRecId{get; set;}
public AccountWrapper(String accName, String accType, String accCity, String accState, String accCtry)
{
this.accName = accName;
this.accType = accType;
this.accCity = accCity;
this.accState = accState;
this.accCtry = accCtry;
this.accRecId = accRecId;
isSelected = false;
}
}
}
Hi Naresh,
Please try below code. you get 100% code coverage.
@isTest
public class TestAccountWrapper {
static testMethod void testAccWra(){
Account objAccount = new Account();
objAccount.Name = 'TestName';
objAccount.Type = 'TestType';
objAccount.BillingCity = 'Ahm';
objAccount.BillingState = 'Guj';
objAccount.BillingCountry = 'Ind';
insert objaccount;
Contact objContact = new Contact();
objContact.LastName = 'TestLastName';
insert objContact;
WrapperClassController.AccountWrapper wrapAcc = new WrapperClassController.AccountWrapper(objAccount.Name,objAccount.Type,objAccount.BillingCity,objAccount.BillingState,objAccount.BillingCountry);
WrapperClassController controller = new WrapperClassController();
controller.ProceedAction();
}
}
Thanks,
Sagar Lakhani
You're welcome anytime roy.....
Thanks,
Sagar Lakhani