Skip to main content
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!
6 件の回答
  1. 2015年10月20日 18:17

    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! :)
0/9000