You need to sign in to do that
Don't have an account?

TEST CLASS FOR CUSTOM CONTROLLER WHICH RETRIVES ACCOUNT RECORDS WITH CHECKBOX
ListOfAccounts VfPage
SelectedAccounts VfPage
Controller1-->Custom Controller
Can Anyone help me with test class for above controller
<apex:page controller="Controller1" > <apex:form > <apex:PageBlock title="Account"> <apex:outputLabel value="Enter Account Name: "> <apex:inputText value="{!AccountName}"/> </apex:outputLabel> <apex:commandButton value="Search" action="{!Display}"/> </apex:PageBlock> <apex:pageBlock title="The list of account are" rendered="{!b2}"> <apex:outputText value="{!Error}"></apex:outputText> </apex:pageBlock> <apex:pageBlock title="The list of account are" rendered="{!b1}"> <apex:pageBlockTable value="{!acclist}" var="b"> <apex:column headerValue="Action"> <apex:inputCheckbox value="{!b.Checked}"/> </apex:column> <apex:column value="{!b.acc.Name}"/> </apex:pageBlockTable> <apex:pageBlockButtons > <apex:commandbutton value="Get Details" action="{!Details}" /> </apex:pageBlockButtons> </apex:PageBlock> </apex:form> </apex:page>
SelectedAccounts VfPage
<apex:page controller="Controller1" > <apex:pageBlock Title="Details of selected accounts are"> <apex:pageBlockTable value="{!Selected}" var="c"> <apex:column value="{!c.id}" /> <apex:column value="{!c.Name}"/> <apex:column value="{!c.type}"/> </apex:pageBlockTable> </apex:pageBlock> </apex:page>
Controller1-->Custom Controller
public class Controller1 { public string AccountName{Get;Set;} public list<waccount> acclist{Get;Set;} public list<Account> selected{Get;Set;} public boolean b1{Get;Set;} public boolean b2{Get;Set;} public string Error{Get;Set;} public void Display() { if(acclist==null) { acclist=new list<waccount>(); list<Account> ls=[select name,type from account where name=:AccountName]; if(ls.size()>0) { b1=true; for(Account a:ls) { acclist.add(new waccount(a)); } } else { b2=true; Error='No Account Found with that name'; } } } public PageReference Details() { selected=new List<Account>(); for(waccount w:acclist) { if(w.checked==true) { selected.add(w.acc); } } return page.SelectedAccounts; } public class waccount { public Account acc{get;set;} public boolean checked{get;set;} public waccount(Account acc) { this.acc=acc; checked=false; } } }
Can Anyone help me with test class for above controller
Try this code Please let me know if that helps you.
If it helps don't forget to mark this as a best answer!!!