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

please can you help me in wriiting test class for this page
<apex:page tabStyle="Account" controller="ShowdDetailCtrl">
<apex:sectionHeader title="Inline Edit Support" subtitle="Account"/>
<apex:form >
<apex:pageBlock title="Account Detail Page">
<apex:pageBlockButtons LOcation="top">
<apex:commandButton value="Save" action="{!saveAccount}"/>
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!lstAccountObjs}" var="acc">
<apex:variable value="{!0}" var="count"/>
<apex:column headerValue="Select">
<apex:facet name="header">
<apex:outputPanel >
Select <input type="checkbox" id="selectAll" name="selectAll" onclick="selectAllOrNone();" />
</apex:outputPanel>
</apex:facet>
<apex:inputCheckbox styleClass="selectAccount" value="{!acc.isSelected}"/>
</apex:column>
<apex:column headerValue="Account Name">
<apex:inputtext value="{!acc.name}"/>
</apex:column>
<apex:column headerValue="Phone">
<apex:inputtext value="{!acc.phone}"/>
<apex:commandLink value="Remove" action="{!removeAccount}">
<apex:param name="c" assignTo="{!count}" value="{!count}"/>
</apeX:commandlink><br/>
<apex:variable value="{!count+1}" var="count"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
<script>
function selectAllOrNone(){
var isSelected = document.getElementById('selectAll').checked;
var elements = document.getElementsByClassName('selectAccount');
for (var i = 0; i < elements.length; i++) {
document.getElementsByClassName('selectAccount')[i].checked = false;
}
if(isSelected){
var elements = document.getElementsByClassName('selectAccount');
for (var i = 0; i < elements.length; i++) {
document.getElementsByClassName('selectAccount')[i].checked = true
}
}
}
</script>
</apex:page>
class------------------------------------------------------------------------------------
public class ShowdDetailCtrl {
public list<AccountObj> lstAccountObjs {get;set;}
public Integer count { get; set; }
//CONSTRUCTOR
public ShowdDetailCtrl(){
init();
}
public void init(){
lstAccountObjs = new list<AccountObj>();
for(Account acc : [select id,name,phone from account limit 5]){
lstAccountObjs.add(new AccountObj(acc));
}
}
public PageReference removeAccount() {
lstAccountObjs.remove(count-1);
return null;
}
public PageReference saveAccount() {
List<Account> lstAccounts = new List<Account>();
if(lstAccountObjs.size() > 0){
for(AccountObj accObj : lstAccountObjs){
if(accObj.isSelected){
System.debug('###CHeckBox'+accObj.name);
Account acc = new Account();
acc.Name = accObj.name;
acc.phone = accObj.phone;
acc.Id = accObj.accId;
lstAccounts.add(acc);
}else{
System.debug('###CHeckBoxElse '+accObj.name);
}
}
System.debug(lstAccounts.size());
for(Account a : lstAccounts){
System.debug('###listItere'+a.name);
}
if(lstAccounts.size() > 0){
update lstAccounts;
}
init();
}
return null;
}
public class AccountObj{
public Boolean isSelected{get; set;}
public String name{get; set;}
public String phone{get; set;}
public String accId{get; set;}
public AccountObj(Account acc){
this.isSelected = false;
this.name = acc.Name;
this.phone = acc.Phone;
this.accId = acc.Id;
}
}
}
@istest
public class ShowdDetailCtrl _test
{
public static testmethod void testmod()
{
// creating a dummy account
boolean checkbox =true;
Account acc = new Account();
acc.name = 'test1';
acc.phone = '123456';
insert acc;
// instantation of the class
ShowdDetailCtrl wc = new ShowdDetailCtrl ();
wc.init();
wc.lstAccountObjs.get(0).isselected = true;
wc.count = 1;
wc.saveAccount();
wc.removeAccount();
}
}
please mark this as best answer if you got the solution .