You need to sign in to do that
Don't have an account?
Sum value that is within apex:repeat
Well, I was finally able to get one of my related lists (Cases), which is part of a custom object (X360_Contract_Cycle__c), to display properly. I am using apex:repeat to iterate and display the related list information. So far that is working great! Now I am trying to figure out the best solution to SUM on of the values within the related list/apex:repeat. The value I am trying to SUM is {!cx.Case_Hours__c}. I included a snippet of the code below. I am wondering if I can include the logic directly on the VisualForce page or would I need to create a custom Apex class? Any suggestions would be much appreciated as I am still learning. Thanks!
<apex:page standardController="X360_Contract_Cycle__c" showHeader="false" renderAs="pdf"> . . . <tr> <td>Case Number</td> <td>Case Subject</td> <td>Case Hours</td> </tr> <apex:repeat var="cx" value="{!X360_Contract_Cycle__c.Cases__r}"> <tr> <td>{!cx.CaseNumber}</td> <td>{!cx.Subject}</td> <td>{!cx.Case_Hours__c}</td> <apex:variable var="Total" value="{SUM(!cx.Case_Hours__c}"/> <td>{!Total}</td> </tr> </apex:repeat> </apex:page>
You can do the following:-
1. You can have a trigger on case on inset, delete, update event you can modify the sum of Cx_Case_Hours__c in this trigger.
2. Also you can use java script code to find the repeat column values and add them through loop which will display in the html variable
3. Or can use a separate function in your controller for the above calculation.
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
All Answers
You can do the following:-
1. You can have a trigger on case on inset, delete, update event you can modify the sum of Cx_Case_Hours__c in this trigger.
2. Also you can use java script code to find the repeat column values and add them through loop which will display in the html variable
3. Or can use a separate function in your controller for the above calculation.
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
Yes, that answering my question. Figuring out the JavaScript and/or function is another issue all together :smileywink:. Thanks for the response.
~ Sean
Hello,
I haven't test it, but something like that should give you the running sum and the total on the last row.
pls provide me error free code of this example plss
thank you
You also need to add a condition to handle null values because they would mess the calculation up.