You need to sign in to do that
Don't have an account?
Jay 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!!
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!!
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.!