You need to sign in to do that
Don't have an account?
JoshTonks
Invalid field field_name__c for AggregateResult
Hi,
I need some guidance on to what im not doing correctly.
Im trying to build a custom controller which gets the number of 3 fields on records that are due to be shipped in the next few days grouped by date.
All these fields are number formula fields with no decimal points. And display as 0 as default value if there is no number in fields it pulls from. Ive never done Aggregate results.
I need some guidance on to what im not doing correctly.
Im trying to build a custom controller which gets the number of 3 fields on records that are due to be shipped in the next few days grouped by date.
public class LogisticsQuantity { //your main class // Date STARTDAY = Date.today(); Date ENDDAY = STARTDAY.addDays(5); public Summary[] Summaries { get; set; } public LogisticsQuantity() { AggregateResult[] results = [ SELECT Last_Date_for_Dispatch__c, Count(Id),SUM(Hard_Wired_Dash_Camera__c), SUM(New_Unit_Qty__c), SUM(Service_Unit_Qty__c) FROM Unit_Request__c WHERE Last_Date_for_Dispatch__c >= :STARTDAY AND Last_Date_for_Dispatch__c < :ENDDAY GROUP BY Last_Date_for_Dispatch__c ]; Summaries = new List<Summary>(); for (AggregateResult ar : results) { Summaries.add(new Summary(ar)); } } // wrapper class to hold aggregate data public class Summary { public Integer NewQuantity { get; set; } public Integer SvcQuantity { get; set; } public Integer CamQuantity { get; set; } public String Name { get; set; } public Summary(AggregateResult ar) { CamQuantity = (Integer) ar.get('Hard_Wired_Dash_Camera__c'); NewQuantity = (Integer) ar.get('New_Unit_Qty__c'); SvcQuantity = (Integer) ar.get('Service_Unit_Qty__c'); Name = (String) ar.get('Last_Date_for_Dispatch__c'); } } }I created a visualforce page to test it out on.
<apex:page controller="LogisticsQuantity"> <apex:form > <apex:repeat value="{!Summaries}" var="summary"> {!summary.Name}: {!summary.NewQuantity} {!summary.SvcQuantity} {!summary.CamQuantity}<br/> </apex:repeat> </apex:form> </apex:page>Its blank when there isnt any records that meet any of the criteria but i get Invalid field field_name__c for AggregateResult. Its happening for all 3 fields that im trying to get SUM of.
All these fields are number formula fields with no decimal points. And display as 0 as default value if there is no number in fields it pulls from. Ive never done Aggregate results.
Please find below the class and page..I tried in dev org and getting results... hope it helps
Apex Class:
VF page: Results:
Kindly mark this as solved if it's resolved so that it gets removed from the unanswered queue.
Thanks,
Sangeetha A