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
Anuradha HiremathAnuradha Hiremath 

Display Standard Account Object Records on VF Page

Hi everyone,
I am learning SF....And now i am at the stage where i have been given a assignment and it says:
1)Need to fetch all the Account records on my VF Page...
2)I have written the Query as : Select AccountNumber,Account.Name From Account...
3) I have created a VF Page and also binded it with custom Controller...
4) Now i want to fetch the AccountNumber and AccountName on the VFPage...How should i write my program on VFPage as well as Controller.....

I tried doing it myself, didn't work up to the expectation..
Any suggestions would be valuable..

VFPage
User-added image
ControllerPage
User-added image
Hemant_JainHemant_Jain
See below code:

Method 1: With Controller Class:

Apex Class: 
public with sharing class StandardAccountDisplayController{ 
public List<Account> records {get; set;} 
public StandardAccountDisplayController(){ 
records = [select Name, AccountNumber from Account]; 
} 
}
Visual Force Page:
<apex:page controller="StandardAccountDisplayController"> 
	<apex:pageBlock title="Account List"> 
		<apex:pageBlockTable value="{!records}" var="record"> 
			<apex:column > 
				<apex:facet name="header">Account Name</apex:facet> 
				<apex:outputText value="{!record.Name}"/> 
			</apex:column> 
			<apex:column > 
				<apex:facet name="header">Account Number</apex:facet> 
				<apex:outputText value="{!record.AccountNumber}"/> 
			</apex:column> 
		</apex:pageBlockTable> 
	</apex:pageBlock> 
</apex:page>

Method 2: WIthout Controller Class.

You can also use the standard controller to display the records in your visualforce page.

Here is the sample code to display all accounts in the visualforce page. No Controller(Apex Class) Required.
 
<apex:page standardController="Account" recordSetVar="accounts" tabstyle="account" sidebar="false">
  <apex:pageBlock >
    <apex:form >
      <apex:pageBlockTable value="{!accounts}" var="a" id="list">
        <apex:column value="{!a.name}"/>
        <apex:column value="{!a.AccountNumber}" />
      </apex:pageBlockTable>
    </apex:form>
  </apex:pageBlock>
</apex:page>

If this clarifies and resolves your query kindly mark this as best answer :)

 
Ramssf70Ramssf70
Hi Anuradha Hiremath,
If you want to get all records in account then you do not need to write apex class with out writing apex class also you can get the record using bellow code but if you want to get particular records then you need to write apex class.
 
<apex:page controller="accountrecordsclass">
<apex:form>
<apex:pageBlock>
<apex:pageBlockTable value="{!acclist}" var="acc">
<apex:column headerValue="Accountname">
<apex:outputText value="{!acc.name}"/>
</apex:column>
<apex:column headerValue="Account Number">
<apex:outputText value="{!acc.accountnumber}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
if you want to get paricular records only particular records use bellow code

apexclass:
public class accountrecordsclass
{
public LIst<account> acclist{get;set;}

public accountrecordsclass()
{
acclist =[seelct id,name,accountnumber from account limit 10];

//write the query according to your requirement
}


}










}
visuval force page 
 
<apex:page controller="accountrecordsclass">
<apex:form>
<apex:pageBlock>
<apex:pageBlockTable value="{!acclist}" var="acc">
<apex:column headerValue="Accountname">
<apex:outputText value="{!acc.name}"/>
</apex:column>
<apex:column headerValue="Account Number">
<apex:outputText value="{!acc.accountnumber}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>


Thank you
 
Soundar Rajan PonpandiSoundar Rajan Ponpandi
Hi HemantJain,

Really Nice Expalaination to Freshers.

Thanks,
Soundar.
vinod kumar 541vinod kumar 541
In Vf page display the updated field value. In the account object custom text field have value ' abc'.

      I want to update that value into 'xyz' and show in vf page. Write the apex class controller for this scenario.