You need to sign in to do that
Don't have an account?
SFDC L
Calculations on 2 separate AggregateResult lists
I'm using AggregateResult to display 2 values, first is a sum of a custom field Hours_Used__c which is in a custom object Holiday__c. Second is a sum of a custom field Hours_Available__c which is on the User object.
I am able to show these results separately on my visualforce page shown here:
My requirement is to be able to display Hours_Available__c - Hours_Used__c to leave me with a column that shows the Staff Member Name and the total hours that are left.
For example using the screenshot above I would need a pageblocktable that shows:
Staff Member | Hours Left
Adam west | 252
Duke Young | 225
Jim Taylor | 198
Controller:
VF Page:
Any help would be greatly appreciated. I'm pretty new to programming in general so i'm open to suggesstions if i'm going about this the wrong way.
Thanks
L
I am able to show these results separately on my visualforce page shown here:
My requirement is to be able to display Hours_Available__c - Hours_Used__c to leave me with a column that shows the Staff Member Name and the total hours that are left.
For example using the screenshot above I would need a pageblocktable that shows:
Staff Member | Hours Left
Adam west | 252
Duke Young | 225
Jim Taylor | 198
Controller:
public class HolidayManagementController { Public List<Holiday__c> HolidayList {get;set;} Public List<AggregateResult> HoursUsedList; Public List<AggregateResult> AllowanceTotalList; String cname {get;set;} Public HolidayManagementcontroller(){ cname = UserInfo.getUserName(); user cu = [SELECT Name FROM User WHERE username =:cname]; HolidayList = [SELECT Hours_Used__c, Staff_Member__c, Staff__r.Name, Manager_Name__c FROM Holiday__c WHERE Manager_Name__c =:cu.Name ORDER BY Staff__r.Name]; HoursUsedList = [SELECT SUM(Hours_Used__c) hours, Staff__r.Name staff FROM Holiday__c WHERE Manager_Name__c =:cu.Name GROUP BY Staff__r.Name ORDER BY Staff__r.Name asc]; AllowanceTotalList = [SELECT SUM(Hours_Available__c) allowance, Name FROM User WHERE Manager__c =:cu.Name GROUP BY Name ORDER BY Name asc]; } public list<AggregateResult> HoursList { get { return HoursUsedList;} } public list<AggregateResult> AllowanceList { get { return AllowanceTotalList;} } }
VF Page:
<apex:page controller="HolidayManagementController" sidebar="false"> <apex:form> <apex:pageBlock> <apex:pageBlockTable value="{!HolidayList}" var="hlist"> <apex:column headerValue="Staff Member"> <apex:outputField value="{!hlist.Staff__r.Name}"/> </apex:column> <apex:column headerValue="Manager"> <apex:outputField value="{!hlist.Manager_Name__c}"/> </apex:column> <apex:column headerValue="Hours Used"> <apex:outputField value="{!hlist.Hours_Used__c}"/> </apex:column> </apex:pageBlockTable> </apex:pageBlock> <apex:pageBlock> <apex:pageBlockTable value="{!HoursList}" var="h"> <apex:column > <apex:facet name="header">Staff Member</apex:facet> {!h['staff']}</apex:column> <apex:column > <apex:facet name="header">Hours Used</apex:facet> {!h['hours']}</apex:column> </apex:pageBlockTable> <apex:pageBlockTable value="{!AllowanceList}" var="a"> <apex:column > <apex:facet name="header">Staff Member</apex:facet> {!a['Name']}</apex:column> <apex:column > <apex:facet name="header">Hours Available</apex:facet> {!a['allowance']}</apex:column> </apex:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page>
Any help would be greatly appreciated. I'm pretty new to programming in general so i'm open to suggesstions if i'm going about this the wrong way.
Thanks
L
Controller
VisualForce Page
NOTE: This code has not been tested and may contain typographical or logical errors
All Answers
Controller
VisualForce Page
NOTE: This code has not been tested and may contain typographical or logical errors
Here is my current code (haven't implemented the UserID change as of yet):
(Controller) (Visualforce Page)