You need to sign in to do that
Don't have an account?
John Neff
Trying to dynamically group & display query results - trouble with Array
Hello,
I am trying to create a page where I can dynamically group querry results, and am using the code in this blog post as a template: template (http://blog.jeffdouglas.com/2011/03/02/dynamically-group-display-query-results/)
The difference is that I am trying to do this with a custom object instead of a standard object.
Here is my controller:
and here is my vf page:
but I am getting the following error:
What can I do to make this work with a custom object? And more importantly, where am I currently going wrong?
Thanks in advance!
John
I am trying to create a page where I can dynamically group querry results, and am using the code in this blog post as a template: template (http://blog.jeffdouglas.com/2011/03/02/dynamically-group-display-query-results/)
The difference is that I am trying to do this with a custom object instead of a standard object.
Here is my controller:
public with sharing class DisplaySectionsController { public List<PI_Vendor__c> vendors {get;set;} public String[] states {get;set;} public void load() { vendors = [Select ID, Name, State__c from PI_Vendor__c WHERE State__c IN ('DE','PA','MD')]; Set<String> stateSet = new Set<String>(); for (PI_Vendor__c v : vendors) stateSet.add(v.State__c); states = new String[stateSet.size()]; Integer i = 0; for (String state : stateSet) { states[i] = state; i++; } } }
and here is my vf page:
<apex:page controller="DisplaySectionsController" action="{!load}" sidebar="false"> <apex:sectionHeader title="My Sample Display Page" subtitle="Group by States" description="This page shows how you can dynamically group results by field value."/> <apex:repeat value="{!states}" var="state"> <apex:pageBlock title="{!state}"> <apex:repeat value="{!vendors}" var="vnd"> <apex:outputPanel rendered="{!IF(state=vendors.State__c,true,false)}"> {!vnd.Name} - {!vnd.State__c}<br/> </apex:outputPanel> </apex:repeat> </apex:pageBlock> </apex:repeat> </apex:page>
but I am getting the following error:
Error: Unknown property 'VisualforceArrayList.State__c'
What can I do to make this work with a custom object? And more importantly, where am I currently going wrong?
Thanks in advance!
John
vendorMap = new Map<String, List<PI_Vendor__c> >();
All Answers
However, I am not sure this is the most efficent way to get what you want. It would be more efficent to build a List of states and then a Map that corresponds. That would prevent pointless looping. I modified your code below:
vendorMap = new Map<String, List<PI_Vendor__c> >();