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
Jay Choi 38Jay Choi 38 

Aggregate Query pull from VisualForce page

Hi, I have error "Invalid field nme for SObject AggregateResult"
From VisualForce Page 

Here is my apex controller
public class BatchListController {
    public Id venue {get; set;}
    
    Public List<Batch__c> Batches = new List<Batch__c>();   
    Public AggregateResult[] agr {get{
        return [SELECT Name nme, count(Job__r.Id) cntid, count(Job__r.Name) cntnme, max(BatchDate__c) cntdt, count(VenueBatch__r.Name) cntvn FROM Batch__c GROUP BY Name];
        
        
    } set;}
    
    Public BatchListController() {
        system.debug('==>JobListController  is calling==>');
        Batches = [SELECT Name,Job__r.Id, Job__r.Name, BatchDate__c, VenueBatch__r.Name FROM Batch__c];
        
    }
    public List<Batch__c>getBatches(){
        
        return Batches;
    }
    public List<Batch__c>setBatches(List<Batch__c>temp){
        
        Batches = temp;
        return Batches;
    }
}

And here is my visualforce page 

<apex:page controller = "BatchListController">
    
    <apex:form>
    
    <apex:PageBlock title="Batch List" id="Jobs_List" >
        
        <apex:pageBlockTable value = "{!agr}" var = "a">
             
            <apex:column style="width:350px" headerValue="Batch" value="{!a['nme']}"/>
            <apex:column style="width:350px" headerValue="#of Jobs " value="{!a['cntid']}"/>
            <apex:column style="width:350px" headerValue = "# of Venue " value="{!a['cntvn']}"/>
            <apex:column style="width:350px" headerValue = "Batch Date" value="{!a['cntdt']}"/>
        </apex:pageBlockTable>
        
        </apex:PageBlock>
        
        <apex:pageBlock title = "Work Order" id = "Work_Order">
        
        
            
        </apex:pageBlock>
    
    </apex:form>
</apex:page>

I am dealing with this for an hour but I don't know where I am wrong. 
Thank you!!
Best Answer chosen by Jay Choi 38
Karan KeharKaran Kehar
Hi Jay,

You cannot use a['nme'] for aggregate result. You should use a.get('nme') in your apex assign it a propery and use in VF.

if this resolves your concern please mark this as best answer.!