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
Aneesh AllumallaAneesh Allumalla 

Showing list on Vf page

I am trying to show the list of account records on vf page:
there is no error. But it is not retrieving any list on vf page.
can someone tell me the reason.
Class:
public class Dev12 {
    public String city{get;set;} 
    public list<account> acclist{get;set;}
    public boolean showTable{get;set;}
    Public Dev12(){
        showTable=false;
}
    Public void showT(){
        List <account> acclist = new List<account>();
        acclist = [Select name , phone, BillingCity from account  where name =:city];
    showTable=true;
    }
}

Vf page:
<apex:page controller="Dev12">
    <apex:form >
    <apex:pageBlock >
        <apex:pageblocksection >
            <apex:inputtext value="{!city}" label="City"/>
            
        </apex:pageblocksection>
        <apex:pageBlockButtons >
            <apex:commandButton value="show" action="{!showT}" reRender="table" />
                   </apex:pageBlockButtons>
        <apex:outputPanel id="table">
        <apex:pageBlockTable rendered="{!showTable==true}" value="{!acclist}" var="a">
            <apex:column value="{!a.name}"/>
            <apex:column value="{!a.phone}"/>
           
            </apex:pageBlockTable>
        </apex:outputPanel>
        </apex:pageBlock>
    </apex:form>
</apex:page>
Best Answer chosen by Aneesh Allumalla
Maharajan CMaharajan C
Hi Aneesh,

The issue in the Class:

Don't create the one more List inside the showT Method just instantiate the already declared List:

And if you want to use the City as the Where condition then use the BillingCity in where query.

Please use the below udated code:


public class Dev12 {
public String city{get;set;}
public list<account> acclist{get;set;}
public boolean showTable{get;set;}
Public Dev12(){
showTable=false;
}
Public void showT(){
acclist = new List<account>();   ///// This Line is now changed
acclist = [Select name , phone, BillingCity from account where BillingCity =:city];
showTable=true;
}
}

Can you please Let me know if it helps or not!!!

If it helps don't forget to mark this as a best answer!!!


    Thanks,
    Maharajan.C




 

All Answers

Maharajan CMaharajan C
Hi Aneesh,

The issue in the Class:

Don't create the one more List inside the showT Method just instantiate the already declared List:

And if you want to use the City as the Where condition then use the BillingCity in where query.

Please use the below udated code:


public class Dev12 {
public String city{get;set;}
public list<account> acclist{get;set;}
public boolean showTable{get;set;}
Public Dev12(){
showTable=false;
}
Public void showT(){
acclist = new List<account>();   ///// This Line is now changed
acclist = [Select name , phone, BillingCity from account where BillingCity =:city];
showTable=true;
}
}

Can you please Let me know if it helps or not!!!

If it helps don't forget to mark this as a best answer!!!


    Thanks,
    Maharajan.C




 
This was selected as the best answer
Aneesh AllumallaAneesh Allumalla
Thanks Maharajan.
It was a silly mistake though.
Maharajan CMaharajan C
Aneesh please choose the best answer to close this thread if your issue solved
Aneesh AllumallaAneesh Allumalla
Done.