function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Salesforce####Salesforce#### 

Test class issue : code coverage and getting error: Constructor not defined: [wrapperAccountCont.wrapAccount].<Constructor>(Account, Boolean) at line 20 column 37

getting this error in test class : can you tell me how to reolve the error and how to get 100 % code coverage .
Constructor not defined: [wrapperAccountCont.wrapAccount].<Constructor>(Account, Boolean) at line 20 column 37

My Test class: 
@isTest

public class wrapperAccountCont_test
{
public testmethod static void ttestmeth()
{
wrapperAccountCont wac = new wrapperAccountCont();
wac.processSelected();
wac.reset();

//wrapper funct
boolean checkbox =true;
Account ac = new account();
ac.name='test1';
ac.BillingState = 'actttt';
ac.phone='12345';
insert ac; 

  wrapperAccountCont.wrapAccount wc = new wrapperAccountCont.wrapAccount(ac,true); // getting error 
//taking test variables
Account acc = new Account();
acc.name = 'test1';
acc.phone = '123456';
insert acc;


}
}
=======================================
my class: 
public with sharing class wrapperAccountCont 
{
public List<wrapAccount> wrapAccountList {get; set;}
    public List<Account> selectedAccounts{get;set;}
     public integer accountreset {get;set;}
    
    public wrapperAccountCont()
    {
        if(wrapAccountList == null) {
            wrapAccountList = new List<wrapAccount>();
            for(Account a: [select Id, Name,BillingState, Website, Phone from Account limit 10]) 
            {
                // As each Account is processed we create a new wrapAccount object and add it to the wrapAccountList
                wrapAccountList.add(new wrapAccount(a));
            }
        }
    }
    public void reset()
    {
    accountreset = 0;
    
    }
    public void processSelected() {
    selectedAccounts = new List<Account>();
 
        for(wrapAccount wrapAccountObj : wrapAccountList) 
        {
            if(wrapAccountObj.selected == true) 
            {
                selectedAccounts.add(wrapAccountObj.acc);
            }
        }
    }
 
    // This is our wrapper/container class. In this example a wrapper class contains both the standard salesforce object Account and a Boolean value
    public class wrapAccount {
        public Account acc {get; set;}
        public Boolean selected {get; set;}
 
        public wrapAccount(Account a) 
        {
            acc = a;
            selected = false;
        }
    }
}

vf page: 
<apex:page controller="wrapperAccountCont">
  
  <script type="text/javascript">
        function selectAllCheckboxes(obj,receivedInputID)
        {
            var inputCheckBox = document.getElementsByTagName("input");
            for(var i=0; i<inputCheckBox.length; i++)
            {
                if(inputCheckBox[i].id.indexOf(receivedInputID)!=-1)
                {
                  inputCheckBox[i].checked = obj.checked;
                }
            }
         }
    </script>
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockButtons >
                <apex:commandButton value="Show Selected Accounts" action="{!processSelected}" rerender="table2"/>
                   <apex:commandButton value="Reset All Accounts" action="{!reset}" rerender="table2"/>
            </apex:pageBlockButtons>
 
            <apex:pageblockSection title="All Accounts" collapsible="false" columns="2">
 
                <apex:pageBlockTable value="{!wrapAccountList}" var="accWrap" id="table" title="All Accounts">
                
                    <apex:column >
                        <apex:facet name="header">
                            <apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId')"/>
                        </apex:facet>
                        <apex:inputCheckbox value="{!accWrap.selected}" id="inputId"/>
                    </apex:column>
                    <apex:column value="{!accWrap.acc.Name}" />
                    <apex:column value="{!accWrap.acc.BillingState}" />
                    <apex:column value="{!accWrap.acc.Phone}" />
                </apex:pageBlockTable>
 
                <apex:pageBlockTable value="{!selectedAccounts}" var="c" id="table2" title="Selected Accounts">
                    <apex:column value="{!c.Name}" headerValue="Account Name"/>
                    <apex:column value="{!c.BillingState}" headerValue="Billing State"/>
                    <apex:column value="{!c.Phone}" headerValue="Phone"/>
                </apex:pageBlockTable>
 
            </apex:pageblockSection>
        </apex:pageBlock>
 
  </apex:form>
</apex:page>
===============================
Best Answer chosen by Salesforce####
Dilip_VDilip_V
Try this,
 
public class wrapperAccountCont_test
{
public testmethod static void ttestmeth()
{
wrapperAccountCont wac = new wrapperAccountCont();
wac.processSelected();
wac.reset();

//wrapper funct
boolean checkbox =true;
Account ac = new account();
ac.name='test1';
ac.BillingState = 'actttt';
ac.phone='12345';
insert ac; 

  wrapperAccountCont.wrapAccount wc = new wrapperAccountCont.wrapAccount(ac); // getting error 
//taking test variables
Account acc = new Account();
acc.name = 'test1';
acc.phone = '123456';
insert acc;
wc.selected=true;
wac.processSelected();

}
}
Let me know if it helps.

If it helps make it as best answer.

Thanks.
 

All Answers

Dilip_VDilip_V
try this class
public class wrapperAccountCont_test
{
public testmethod static void ttestmeth()
{
wrapperAccountCont wac = new wrapperAccountCont();
wac.processSelected();
wac.reset();

//wrapper funct
boolean checkbox =true;
Account ac = new account();
ac.name='test1';
ac.BillingState = 'actttt';
ac.phone='12345';
insert ac; 

  wrapperAccountCont.wrapAccount wc = new wrapperAccountCont.wrapAccount(ac); // getting error 
//taking test variables
Account acc = new Account();
acc.name = 'test1';
acc.phone = '123456';
insert acc;


}
}

Let me know if it helps.

If it helps make it as best answer.

Thanks.
Salesforce####Salesforce####
hi the erro ris resolved buut the code coverage is 73 % . the lines which are not covering are 

line 1 :   wrapAccountList.add(new wrapAccount(a));


line 2  :for(wrapAccount wrapAccountObj : wrapAccountList) 
        {
            if(wrapAccountObj.selected == true) 
            {
                selectedAccounts.add(wrapAccountObj.acc);
            }
        }

can you tell me how to cover those lines form above code .. i want 100 %
Dilip_VDilip_V
Try this,
 
public class wrapperAccountCont_test
{
public testmethod static void ttestmeth()
{
wrapperAccountCont wac = new wrapperAccountCont();
wac.processSelected();
wac.reset();

//wrapper funct
boolean checkbox =true;
Account ac = new account();
ac.name='test1';
ac.BillingState = 'actttt';
ac.phone='12345';
insert ac; 

  wrapperAccountCont.wrapAccount wc = new wrapperAccountCont.wrapAccount(ac); // getting error 
//taking test variables
Account acc = new Account();
acc.name = 'test1';
acc.phone = '123456';
insert acc;
wc.selected=true;
wac.processSelected();

}
}
Let me know if it helps.

If it helps make it as best answer.

Thanks.
 
This was selected as the best answer
Salesforce####Salesforce####
@thanks Thermo Dynamics