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
dfpittdfpitt 

Hide related list table headers in VF Email Template, if related list is empty

Hello,

 

I have an email template that shows information from a custom object and from a related list to that custom object. I want to be able to hide the table headers whenever the related list has no records. I have tried using <apex: outputpanel rendered...> but it has n't worked, as I haven't been able to get the size of the list, so that if the outputpanel is rendered when the size is greater than 0.

 

Any ideas would be greatly appreciated.

Best Answer chosen by Admin (Salesforce Developers) 
dfpittdfpitt

I had some trouble implementing your suggestion a while back and I put this on hold.

 

I was able to implement it today via another route.

 

I created a summary field in the parent object that counts the number of records in the related list (Count_RelatedList__c) and then in the VF Email template, I use Rendered="{!relatedTo.Count_RelatedList__c >0}"

All Answers

bob_buzzardbob_buzzard

This sounds very much like something I was doing a while ago (albeit in visualforce pages).  I wrote up a blog post explaining how at:

 

http://bobbuzzard.blogspot.com/2010/10/visualforce-conditional-list-rendering.html

 

You should be able to create the custom components for use in visualforce email templates in much the same way.

dfpittdfpitt

Hi Bob,

 

thanks for your reply.

 

a couple of questions:

- I would have to create a Controller specific to my related list, just like the example one you posted, right?(ListIteratorExampleController)

- How would I bring in the controller into the email? Would I use an <apex:page>?

 

I actually have 4 related list that I want to include in the emai and only show if they have any information.

bob_buzzardbob_buzzard

I think you'll need a controller per list, or higher level controller that converts the related list ot a list of strings.

 

You can include custom components in visualforce email templates, and these have custom controllers backing them.  There's more details at:

 

http://www.salesforce.com/us/developer/docs/pages/index_Left.htm#CSHID=pages_email_templates_with_apex.htm|StartTopic=Content%2Fpages_email_templates_with_apex.htm|SkinName=webhelp

dfpittdfpitt

I had some trouble implementing your suggestion a while back and I put this on hold.

 

I was able to implement it today via another route.

 

I created a summary field in the parent object that counts the number of records in the related list (Count_RelatedList__c) and then in the VF Email template, I use Rendered="{!relatedTo.Count_RelatedList__c >0}"

This was selected as the best answer