You need to sign in to do that
Don't have an account?
Test Method for Custom Controller
Hi
Need help to get test coverage for custom controller calss.
when i tried it is covering on 29%
Controller class
public with sharing class MassUpdateFldSelected {
//Variables
Public List<AccountWrapper> AccountWrapList{get;set;}
Public string inptstring{get;set;}
Public string Selectedfield{get;set;}
Public List<string> fieldsfromfieldset{get;set;}
//Construct Class
public MassUpdateFldSelected(ApexPages.StandardController controller) {
fieldsfromfieldset = new List<string>();
}
Public List<AccountWrapper> getwrapperObj(){
AccountWrapList = New List<AccountWrapper>();
List<Account> accList = [Select id,name,Phone,BillingCity,Website from account limit 20];
for(Account acc: accList){
AccountWrapList.add(New AccountWrapper(acc,false));
}
return AccountWrapList;//AccountWrapList
}
public List<SelectOption> getfieldsfromfs() {
List<SelectOption> fieldssets= new List<SelectOption>();
for(Schema.FieldSetMember fld :SObjectType.account.FieldSets.AccountFeilds.getFields()) {
fieldssets.add(new SelectOption(fld.getFieldPath(),fld.getFieldPath()));
}
return fieldssets;
}
//Method to updated records for selected fields from picklist
Public void updateSelectedRecords(){
List<Account> accountList = New List<Account>();
for(AccountWrapper wr: AccountWrapList){
if(wr.checkBox == true ){
wr.accObj.put(selectedField,inptstring);
}
accountList.add(wr.accObj);
}
Update accountList;
}
//Method to Delete the selected records
Public void deleteRecords(){
List<Account> accToDelList = New List<Account>();
for(AccountWrapper wr: AccountWrapList){
if(wr.checkBox == true ){
accToDelList.add(wr.accObj);
}
}
delete accToDelList;
}
public pagereference BackToHomeBtnClick(){
pagereference homepage = new pagereference('/home/home.jsp');
homepage.setredirect(true);
return homepage ;
}
//Account Wrapper calss
Public Class AccountWrapper{
Public Account accObj{get;set;}
Public Boolean checkBox{get;set;}
Public AccountWrapper(Account accRec, boolean SelectBox){
accObj = accRec;
checkBox = SelectBox;
}
}
}
Test class
@isTest
public class MassUpdateFldSelectedTest{
static testMethod void test(){
account a1 = new account(name='abc test',BillingState = 'UK',Phone = '96589658',Website = 'www.abc.com');
insert a1;
MassUpdateFldSelected massupdt = new MassUpdateFldSelected();
massupdt.updateSelectedRecords();
massupdt.deleteRecords();
massupdt.BackToHomeBtnClick();
//AccountWrapper accwr = new AccountWrapper();
}
}
Can any one pls help out it's very urgent!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Hi Vishnu,
You have to update your Test class as below.
Test class:
Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator
My Blog:- http://mrjavascript.blogspot.in/