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
Dave BerenatoDave Berenato 

Pull Select Query Record into Visualforce Page

I'm looking to display fields from an Account record (including fields from Lookup Objects that the Account is the child record for) and I'm probably missing something super simple but here is my class:
 
public class FileReview {
    
	public FileReview() 
    {myId = ApexPages.currentPage().getParameters().get('id');}
	public string myId {get;set;}
    Account acc = [Select Id,Name FROM Account Where Id = :myId];
}

And Visualforce Page:
 
<apex:page Controller="FAIRFileReview" showheader="false">
   {!acc.Name}
</apex:page>

Error is: "Unknown Property "FileReview.acc"

I tried to write "return acc;" underneath the Apex class but got "Expecting '}' but was: 'return' "
 
Best Answer chosen by Dave Berenato
Raj VakatiRaj Vakati
Class
public class FileReview {
    public string myId {get;set;}
    public Account acc{get;set;}
    public FileReview() 
    {
        myId = ApexPages.currentPage().getParameters().get('id');
        acc = [Select Id,Name FROM Account Where Id = :myId];
    }
    
}

Page
<apex:page Controller="FileReview" showheader="false">
   {!acc.Name}
</apex:page>