+ Start a Discussion
Justin RhoadesJustin Rhoades 

String.name error

I am at a lost for some reason this code will not work and I don't understand why. I am trying to make a table on a visual force page.

Here is the class
public with sharing class stationController 
{
    public List<Account> accounts {get;set;}
    public stationController()
    {
        accounts = [SELECT Id, Name, Customer_Num__c, Location_Number__c, Type  FROM account LIMIT 10];
    }
}

and here is the page
<apex:page controller="stationController">
  <apex:pageBlock title="Stations">
      <apex:pageBlockTable value="{!accounts}>" var="account">
          <apex:column value="{!accounts.name}"/>
      </apex:pageBlockTable>
   </apex:pageBlock>
</apex:page>


The class shows no problem but when I try to get the account name on the visual force page I get the string.name error but if I only call for the account I get teh account ID number just fine.

I have used the exact same code to get contact information and this error never appeared.

 
AmitSahuAmitSahu
<apex:page controller="stationController">
  <apex:pageBlock title="Stations">
      <apex:pageBlockTable value="{!accounts}>" var="account">
          <apex:column value="{!accounts.name}"/>
      </apex:pageBlockTable>
   </apex:pageBlock>
</apex:page>

Can you remove s from the highlighted one and try ?
AshlekhAshlekh
Hi,

Yes as per Amitsahu you are using {!accounts} which is a list and you are refering accounts.name which is wrong.
 
<apex:page controller="stationController">
  <apex:pageBlock title="Stations">
      <apex:pageBlockTable value="{!accounts}>" var="account">
          <apex:column value="{!account.name}"/>
      </apex:pageBlockTable>
   </apex:pageBlock>
</apex:page>

-Thanks
Ashlekh Gera
Justin RhoadesJustin Rhoades
same error appears when I change {!accounts.name} to {!account.name}