+ Start a Discussion
santhi sanapala 5santhi sanapala 5 

details not visible

hi ,

i've written a code to show account details but its not working.kindly help as it is not throwing any error and there is also data in list<Account> in apex class.

Vf code :

<apex:page controller="accountInformation">
<apex:pageblock title="Accounts" >
<!--
<apex:repeat value="{!accs}" var="a">
<apex:pageblocksection >
<apex:outputlabel value="{!a.Name}"/>
<apex:outputfield value="{!a.Phone}"/>
<apex:outputfield value="{!a.Active__c}"/>
<apex:outputfield value="{!a.CleanStatus}"/>
</apex:pageblocksection>
</apex:repeat>
-->
<apex:pageblockTable value="{!accs}" var="a">
<apex:column value="{!a.Name}"/>
<apex:column value="{!a.Phone}"/>
<apex:column value="{!a.Active__c}"/>
<apex:column value="{!a.CleanStatus}"/>

</apex:pageblockTable>

</apex:pageblock>


</apex:page>

apex class:

public class accountInformation {


public list<Account> accs{ get; set;}

public list<Account> getAccounts(){

accs=[select Name,Phone,Active__c,CleanStatus from Account];
system.debug('Account info:'+accs);
return accs;
}

}
Best Answer chosen by santhi sanapala 5
Avishek Nanda 14Avishek Nanda 14
Hi Santhi,

Please find the below code. I have modified your code little bit. 
public with sharing class accountInformation{ 
    public List<Account> accs {get; set;} 
    public accountInformation(){ 
        accs = [select Id,Name,Phone,Active__c,CleanStatus from Account]; 
    } 
}
 
<apex:page controller="accountInformation"> 
    <apex:pageBlock title="Accounts"> 
        <apex:pageBlockTable value="{!accs}" var="a"> 
            <apex:column > 
                <apex:facet name="header">Account Name</apex:facet> 
                <apex:outputText value="{!a.Name}"/> 
            </apex:column> 
            <apex:column > 
                <apex:facet name="header">Account Phone Number</apex:facet> 
                <apex:outputText value="{!a.Phone}"/> 
            </apex:column> 
            <apex:column > 
                <apex:facet name="header">Clean Status</apex:facet> 
                <apex:outputText value="{!a.CleanStatus}"/> 
            </apex:column> 
        </apex:pageBlockTable> 
    </apex:pageBlock> 
</apex:page>

Hope this helps. Mark this as your best answer if this resolves your query. 

Regards,
Avishek Nanda

All Answers

Avishek Nanda 14Avishek Nanda 14
Hi Santhi,

Please find the below code. I have modified your code little bit. 
public with sharing class accountInformation{ 
    public List<Account> accs {get; set;} 
    public accountInformation(){ 
        accs = [select Id,Name,Phone,Active__c,CleanStatus from Account]; 
    } 
}
 
<apex:page controller="accountInformation"> 
    <apex:pageBlock title="Accounts"> 
        <apex:pageBlockTable value="{!accs}" var="a"> 
            <apex:column > 
                <apex:facet name="header">Account Name</apex:facet> 
                <apex:outputText value="{!a.Name}"/> 
            </apex:column> 
            <apex:column > 
                <apex:facet name="header">Account Phone Number</apex:facet> 
                <apex:outputText value="{!a.Phone}"/> 
            </apex:column> 
            <apex:column > 
                <apex:facet name="header">Clean Status</apex:facet> 
                <apex:outputText value="{!a.CleanStatus}"/> 
            </apex:column> 
        </apex:pageBlockTable> 
    </apex:pageBlock> 
</apex:page>

Hope this helps. Mark this as your best answer if this resolves your query. 

Regards,
Avishek Nanda
This was selected as the best answer
santhi sanapala 5santhi sanapala 5
Hi Avishek,

Thank you, your code has worked !!!.

But after i removed soql query from function and placed in constructor (in my code) then only it worked.

please explain me why vf page couldn't fetch accs records from a method when it could fetch accs records successfully from a constructor. Is there any particular reason? or is there anything i have missed in the method.


Regards,
Santhi
 
Avishek Nanda 14Avishek Nanda 14
HI Santhi,
Get method should not be used lyk that. Get method itself return value. U don't need separate variable and And it depends how u call from vf page.
Please Check this link https://www.tutorialkart.com/learn_apex/visualforce-getter-method-and-setter-method which will give you a details idea.

Regards,
Avishek Nanda