function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
FreddySFreddyS 

visual force email template Aggregate Results

Hi,

Im trying to create a visualforce email template that shows a parent object's sum of hours from child records. I have a parent and a child in a lookup relationship where the child has a field Hours__c number field. How do I get the sum of total hours and group by the parent records? I.E. show total hours by Task and then the grand total of hours for all tasks?

Thanks in advance!
Best Answer chosen by FreddyS
Raj VakatiRaj Vakati
You have to do like .. 

Create an Apex class  that will get the aggregate result 
and create a visualforce component page 
call the component from the email template 

Refer to this link 

https://developer.salesforce.com/forums/?id=906F000000098RuIAI
https://salesforce.stackexchange.com/questions/33944/issue-in-displaying-related-object-fields-in-vf-email-template
https://salesforce.stackexchange.com/questions/172610/soql-query-to-get-the-email-template-id?rq=1
http://www.infallibletechie.com/2013/07/aggregateresult-in-salesforce.html


 

All Answers

Raj VakatiRaj Vakati
You have to do like .. 

Create an Apex class  that will get the aggregate result 
and create a visualforce component page 
call the component from the email template 

Refer to this link 

https://developer.salesforce.com/forums/?id=906F000000098RuIAI
https://salesforce.stackexchange.com/questions/33944/issue-in-displaying-related-object-fields-in-vf-email-template
https://salesforce.stackexchange.com/questions/172610/soql-query-to-get-the-email-template-id?rq=1
http://www.infallibletechie.com/2013/07/aggregateresult-in-salesforce.html


 
This was selected as the best answer
FreddySFreddyS
Hey thanks for the resources! I got the page working using this: http://www.infallibletechie.com/2013/07/aggregateresult-in-salesforce.html