Skip to main content
3 of 3
improved formatting
arut
  • 5.4k
  • 2
  • 13
  • 30

Aggregate result not working in soql query

im new to visualforce and i have this problem: I have a sObject with customField1__c, customField2__c, customField3__c.

In my main page (with a standard controller and an extension) i want to display a table in wich i want to see all the customField1__c, customField2__c, customField3__c that are related to my customField1__c.

I'm trying to use a aggregateResult because otherwise i have a lot of duplicates in customField__1, but i have this error:

"Invalid field customField__c for SObject AggregateResult Error is in expression '{!myQuery.customField1}' in component apex:outputText in page myQuery"

here is my main page:

    <table>
        <tr> <th> My table title </th> </tr>
        <tr>
            <td> <b> Field1 </b> </td>
            <td> <b> Fiel2 </b> </td>
            <td> <b> Field3 </b> </td>
        </tr>

        <apex:repeat value="{!myQuery}" var="myQuery">
            <tr>
                <td>  <apex:outputText value="{!myQuery.CustomField1__c}"/> </td>
                <td> <apex:outputText value="{!myQuery.CustomField2__c}"/> </td>
                <td> <apex:outputText value="{!myQuery.CustomField3__c}"/> </td>
            </tr>
        </apex:repeat>
    </table>

Then I have my page Extension:

public with sharing class MyPageExtension {

    public List<AggregateResult> indicatorNotes{get;set;}

    public MyPageExtension(ApexPages.StandardController ctrl) {   

        myQuery=[ SELECT customField1__c, customField2__c, customField3__c
        FROM customObject__c
               GROUP BY customField1__c, customField2__c, customField3__c
        ];

thanks in advance