We have a custom VF page that we use in our Org for time entry, and on that page employees select a project, iteration, and enter their time for that week. Note: some employees might be working on different projects and different iterations in the same week.
I'm supposed to display the total hours ,for each iteration, that has been worked by that employee , so I'm using AggregateResult SUM().
My code for getting the sum is :
list<AggregateResult> iterationResults = [select SUM(duration__c) sumDuration
from time_entry__c
where User__c = :UserID
group by Iteration__c];
I threw a system debug to make sure it works:
for (AggregateResult ar: iterationResults) {
decimal dec1 = (Decimal)ar.get('sumDuration');
system.debug('\n Target is : \n' + dec1);
}
I'm getting the correct SUM, which is good, but that decimal variable holds the right value but without differentiating between iterations. So here are the two things that i'm stuck on:
- How can I assign the SUM of each iteration to a variable where I can pass that value to my VF page?
- I understand that I cannot bind VF components to AggregateResult, so I'll need a wrapper class. How is my wrapper class going to look like?
Additional detail that might be helpful is the query I use to get the projects/iterations data from database:
[select id, Memo__c, project__r.name, iteration__r.name, Milestones_PM_Task__r.name, date__c, day_of_week__c, duration__c
from time_entry__c
where User__c = :UserID
and date__c >= :firstDate and date__c < :lastDate
order by project__r.name, iteration__r.name, date__c, createddate ]
I really appreciate your effort and help