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
Dennis GravesDennis Graves 

Check if related list is empty on visualforce page

I have an object model that has a related list, and on a Visualforce page I am displaying a fully custom UI for this related list.

The issue is that I need to only display a section if the related list has records, but due to the styling there is a div that is outside the repeater that needs to be hidden if the related list is empty.

I attempted using the .size(), ISNULL, ISEMPTY on the visualforce page, but those don't work, either they throw an error or don't return the expected results.

Is there a way to determine if a related list is populated without using a custom apex extension or including a rollup field that counts the number of related objects?
Nilesh Jagtap (NJ)Nilesh Jagtap (NJ)
Hi Dennis,

We had come across the same requirement in one of the project to show realated list on custom page with related list linklets at the top as we have in standard page.
It would be great if you can share some sample code for it.

Thanks !!
Denis VakulishinDenis Vakulishin
<apex:pageBlockTable ... rendered="{!contacts.size>0}">

James LoghryJames Loghry
Or you can use <apex:pageBlockTable ... rendered="{!NOT(contacts.empty)}">  (I've noticed in some cases > and < mess with the rendered attribute)
Denis VakulishinDenis Vakulishin
Or
<apex:pageBlockTable ... rendered="{!contacts.size!=0}">
Actually, I agree with James. Using ">" or "<" symblols is not good in HTML page (or visualforce)
So, you have 3 possible option =)
Matti SchviliMatti Schvili
I can't access size, empty etc for the relation. Both Master and Slave are custom objects and the relationship through a Master-Detail type. Any help in solving this would be much welcome.