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
Kishore Ravi 2Kishore Ravi 2 

Unable to call method to VF page / save VF

Hi Experts,

Am trying to call a method into VF, but am getting the below error
User-added image


here is my class

Public class RBGeneratorController{
List<account> selectacct;


Public List<account> getAllAccounts()
{
    List<account> allaccts = [Select ID,Name, Industry, Type, Billingstreet from Account limit 5];
   return allaccts;
}    


Public void selectacct()
{
    String selaccountid = System.currentPagereference().getParameters().get('accid');
    Account acc = [Select ID,Name, Industry, Type, Billingstreet from Account where Id=:selaccountid];
    selectacct =  new List<account>();
    selectacct.add(acc);
}
//Public List<account> getselectedAccount()
//{
 //   return selectacct;
//}
}


here is VF page


<apex:page>
<apex:form>
<apex:pageblock id="PB" title="Available Generators">
               <apex:pageblocktable id="PBT" value="{!AllAccounts}" var="allaccts">
                    <apex:column headervalue="Generatos">                    
                       <apex:actionsupport action="{!selectacct}" event="onclick" rerender="allcons">  
                        <input type="radio" />                    
                            <apex:param name="accid" value="{!allcon.Id}">
                        </apex:param></apex:actionsupport>                            
                    </apex:column>    
                    <apex:column headervalue="Name">
                        <apex:outputfield value="{!allcon.Name}">
                    </apex:outputfield></apex:column> 
                    <apex:column headervalue="Industry">
                        <apex:outputfield value="{!allcon.Industry}">
                    </apex:outputfield></apex:column>  
                    <apex:column headervalue="Type">
                        <apex:outputfield value="{!allcon.Type}">
                    </apex:outputfield></apex:column>  
                    <apex:column headervalue="BillingStreet">
                        <apex:outputfield value="{!allcon.Billingstreet}">
                    </apex:outputfield></apex:column>  
                </apex:pageblocktable>
</apex:pageblock>

</apex:form>

</apex:page>

please help me through this

Thank you
Amit Chaudhary 8Amit Chaudhary 8
I did some changes in your VF page and added below link in code
<apex:page controller="RBGeneratorController">



Please try below code :-
<apex:page controller="RBGeneratorController">
<apex:form >
    <apex:pageblock id="PB" title="Available Generators">
                   <apex:pageblocktable id="PBT" value="{!AllAccounts}" var="allaccts">
                        <apex:column headervalue="Generatos">                    
                           <apex:actionsupport action="{!selectacct}" event="onclick" rerender="allcons">  
                            <input type="radio" />                    
                                <apex:param name="accid" value="{!allaccts.Id}">
                            </apex:param></apex:actionsupport>                            
                        </apex:column>    
                        <apex:column headervalue="Name">
                            <apex:outputfield value="{!allaccts.Name}">
                        </apex:outputfield></apex:column> 
                        <apex:column headervalue="Industry">
                            <apex:outputfield value="{!allaccts.Industry}">
                        </apex:outputfield></apex:column>  
                        <apex:column headervalue="Type">
                            <apex:outputfield value="{!allaccts.Type}">
                        </apex:outputfield></apex:column>  
                        <apex:column headervalue="BillingStreet">
                            <apex:outputfield value="{!allaccts.Billingstreet}">
                        </apex:outputfield></apex:column>  
                    </apex:pageblocktable>
    </apex:pageblock>
</apex:form>
</apex:page>
 
Public class RBGeneratorController
{
    List<account> selectacct;

    Public List<account> getAllAccounts()
    {
        List<account> allaccts = [Select ID,Name, Industry, Type, Billingstreet from Account limit 5];
        return allaccts;
    }    

    Public void selectacct()
    {
        String selaccountid = System.currentPagereference().getParameters().get('accid');
        Account acc = [Select ID,Name, Industry, Type, Billingstreet from Account where Id=:selaccountid];
        selectacct =  new List<account>();
        selectacct.add(acc);
    }
    
    //Public List<account> getselectedAccount()
    //{
     //   return selectacct;
    //}
}
Please mark this as solution if this will help you.



 
surasura
try below code , you must have class level varaible called Allaccounts. replace your class with below code
Public class RBGeneratorController{
List<account> selectacct;
public list<account> AllAccounts;

Public List<account> getAllAccounts()
{
    List<account> accountlist= [Select ID,Name, Industry, Type, Billingstreet from Account limit 5];
   return accountlist;
}    


Public void selectacct()
{
    String selaccountid = System.currentPagereference().getParameters().get('accid');
    Account acc = [Select ID,Name, Industry, Type, Billingstreet from Account where Id=:selaccountid];
    selectacct =  new List<account>();
    selectacct.add(acc);
}
//Public List<account> getselectedAccount()
//{
 //   return selectacct;
//}
}
justin_sfdcjustin_sfdc
Hi Kishore,
The error is because you are calling "AllAccounts" in your VFpage but the reference does not exist in the controller.

In your VF page, you have: (in Line#4)
 <apex:pageblocktable id="PBT" value="{!AllAccounts}" var="allaccts"> 

Therefore, you'll have to add the reference onto the controller, like this:
public list<Account> AllAccounts {get; set;}

This should resolve your issue!

Thanks!