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
Tony66Tony66 

Display list of records in visualforce using SOQL query

Hello guys, I have a vf page on workorder object. When I open the vf page on a wo record whose account name is ABC and po number (custom field) is 123 for example, I want to display a list of all the work orders who have the same account and the po number. How do I query and display these set of records as a custom related list on the visualforce page? 
AbhishekAbhishek (Salesforce Developers) 

Hi Tony,

Whenever you want to display something in a visual force page you have to write get method or get property
like  public list<Account> accs {get;set;}
 
try this:
 
Vf Page
public class ClassRetrieve {
public list<Account> accs {get;set;}
public ClassRetrieve()
{
accs = [Select Id, Name, (Select Id, Name From Contacts) From Account];
}
}
 
Class :
 
<apex:page controller="ClassRetrieve">
<apex:pageBlock >
<apex:pageBlockTable value="{!accs}" var="a">
<apex:column value="{!a.Name}"/>
<apex:column value="{!a.Id}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks.