Print this page

Display result of a SOQL query on a visualforce page

Knowledge Article Number 000205631
Description Example to create a visualforce page to display results of a SOQL query:
1) Create an apex class which retrieves records from a SOQL query
2) Create a visualforce page to display the results returned from this SOQL query
Resolution Apex Class:
public with sharing class TestDisplayQueryList{ 
public List<Account> Records {get; set;} 
public TestDisplayQueryList(){ 
Records = 
[select Name, AccountNumber, CleanStatus from Account where CleanStatus='Pending']; 


Visualforce Page:
<apex:page controller="TestDisplayQueryList"> 
	<apex:pageBlock title="My Content"> 
		<apex:pageBlockTable value="{!Records}" var="Record"> 
			<apex:column > 
				<apex:facet name="header">Account Name</apex:facet> 
				<apex:outputText value="{!Record.Name}"/> 
			<apex:column > 
				<apex:facet name="header">Account Number</apex:facet> 
				<apex:outputText value="{!Record.AccountNumber}"/> 
			<apex:column > 
				<apex:facet name="header">Clean Status</apex:facet> 
				<apex:outputText value="{!Record.CleanStatus}"/> 

promote demote