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
John NeffJohn Neff 

Error: Unknown property 'VisualforceArrayList.name' - How do I solve this?

Hello, 

I am trying to group results in a list by a field value, and am getting stuck.   I am using this article as a model: http://blog.jeffdouglas.com/2011/03/02/dynamically-group-display-query-results/

Here is my controller: 
 
public with sharing class SpotController{

public List <Job_Number__c> SPOT {get;set;}
public String[] campaigns {get;set;}

public void load() {

  SPOT = [Select id, name, Thumbnail_URL__c, ISCI__c, Title__c, Project__c, Campaign__r.Name from Job_Number__c WHERE Currently_Airing__c = TRUE];
  
  Set<String> campaignSet = new Set<String>();
  for (Job_Number__c j : SPOT)
      campaignSet.add(j.Campaign__r.Name);
      
      campaigns = new String[campaignSet.size()];
      Integer i = 0;
      for (String campaign : campaignSet) {
      campaigns[i] = campaign;
      i++;
        }
    }
}
But 
and here is my vf page: 
 
<apex:page controller="SpotController" action="{!load}">
<html>

  <apex:repeat value="{!campaigns}" var="campaign">

    <apex:pageBlock title="{!campaign}">

      <apex:repeat value="{!SPOT}" var="spot">
      
          {!SPOT.name} 

        <apex:outputPanel >
      
        </apex:outputPanel>

      </apex:repeat>

    </apex:pageBlock>

  </apex:repeat>

</html>
</apex:page>


But I am getting an error when I try to pull in any fields from the Job_Number__c object.  Error: Unknown property 'VisualforceArrayList.name'

Can anyone help?  Thanks so much in advance!
Best Answer chosen by John Neff
Chandra Prakash PandeyChandra Prakash Pandey

Hi John,

Just Correction you need to change var property for spot collection repeater from spot to spotObj or something else I.E.

Replace 
<apex:repeat value="{!SPOT}" var="spot">
    {!SPOT.name} 
    <apex:outputPanel >

    </apex:outputPanel>
</apex:repeat>
To
 
<apex:repeat value="{!SPOT}" var="spotObj">
    {!spotObj.name} 
    <apex:outputPanel >

    </apex:outputPanel>
</apex:repeat>

by doing this your problem will resolve.


Regards,
Chandra Prakash
Happy Coding! :)

All Answers

Chandra Prakash PandeyChandra Prakash Pandey
Hi John,

Change your var pointer name in repeater from Campaign to Camp or something else and then give it a try.
<apex:repeat value="{!campaigns}" var="camp">

Regards,
Chandra Prakash
Chandra Prakash PandeyChandra Prakash Pandey

Hi John,

Just Correction you need to change var property for spot collection repeater from spot to spotObj or something else I.E.

Replace 
<apex:repeat value="{!SPOT}" var="spot">
    {!SPOT.name} 
    <apex:outputPanel >

    </apex:outputPanel>
</apex:repeat>
To
 
<apex:repeat value="{!SPOT}" var="spotObj">
    {!spotObj.name} 
    <apex:outputPanel >

    </apex:outputPanel>
</apex:repeat>

by doing this your problem will resolve.


Regards,
Chandra Prakash
Happy Coding! :)
This was selected as the best answer
John NeffJohn Neff
Thanks Chandra, I made the swap and it still didn't work. I am trying to take the field values from the controller 
SPOT = [Select id, name, Thumbnail_URL__c, ISCI__c, Title__c, Project__c, Campaign__r.Name from Job_Number__c WHERE Currently_Airing__c = TRUE]

and place them inside each pageblock table like so: 
<apex:repeat value="{!campaigns}" var="camp">

    <apex:pageBlock title="{!camp}">

     <apex:pageBlockTable value="{!SPOT}" var="spot">
        <apex:column value="{!spot.Name}"/>
        <apex:column value="{!spot.ISCI__c}"/>
   
     </apex:pageBlockTable>

    </apex:pageBlock>

  </apex:repeat>

but I am stuck!
John NeffJohn Neff
Chandra that worked!  Thank you so much!
John NeffJohn Neff
Hey Chandra one last question if you don't mind!... how would I put a SORT BY attribute on the Campaign string so that the categories are arranged alphabetically?

Thanks!

John
Chandra Prakash PandeyChandra Prakash Pandey
Hi John,

Very simple just call campaigns.sort(); in your controller.

Regards,
Chandra Prakash