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
SaintMichaelSaintMichael 

Custom Controllers not working

Trying to do soe simple data querying and show to visualforce page.

Here is the VisualForce page:

 

 

<apex:page controller="MyController" > 
  <apex:pageBlock title="Accounts">

<apex:outputPanel >
    <apex:dataTable value="{!myAccounts}" var="aAccount" width="100%" >
     <apex:column >
      <apex:facet name="header"><b>Id</b></apex:facet>

      {!aAccount.Id}
     </apex:column>
     
 <apex:column >
      <apex:facet name="header"><b>Name</b></apex:facet>

      {!aAccount.Name}
     </apex:column>
   </apex:dataTable>                
</apex:outputPanel>




  </apex:pageBlock> 
</apex:page>

 

 

here is the custom controller 'MyController'

 

 

public class MyController {

      public List<Account> getMyAccounts(){
          return [select Id, Name from Account];
      }

     

      
}

 The column headers show up but the data is not coming in. I do have records, so not sure why this isn't working?

 

Best Answer chosen by Admin (Salesforce Developers) 
SaintMichaelSaintMichael

Ok, so the problem was I was testing using the real site url. I used the url that is shown

when using editing the apex class and visualforce pages instead of the real/public site url.

 

Duh!

 

 

All Answers

DharmeshDharmesh

You can put debug statement inside method and check how many record has been return by the query.

I dont see any flaw in code.

cloudcodercloudcoder

I took your code verbatim and it worked just fine. Are you seeing any error messages? If not I would suggest building your Visualforce page a piece at a time. eg: just loop through the results, then add them to a table etc.

SaintMichaelSaintMichael

Ok, so the problem was I was testing using the real site url. I used the url that is shown

when using editing the apex class and visualforce pages instead of the real/public site url.

 

Duh!

 

 

This was selected as the best answer