Render Conditions to include count of records in a related model

  • 2
  • Question
  • Updated 4 years ago
  • Answered
I have a a need to render some different layouts depending on the number of child records on the parent object. e.g. if the parent has only 1 child, the page is shown as 'one', where we mash up the two records into a single view. Between 2 and 4 we nest the children below, and more than 4, we provide a list.

How do I create the render condition that queries the number of records in a model?
Photo of Ross James

Ross James

  • 490 Points 250 badge 2x thumb
  • excited

Posted 5 years ago

  • 2
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,556 Points 20k badge 2x thumb
Option 1: create a Roll-up Summary field on your parent model called "# of Children", that just does a COUNT on the number of children. Then you could base your Render Conditions on the "# of Children" field on the parent Model.

Option 2: use JavaScript to listen for row creation / deletion events on the parent Model and then apply your own custom logic to decide which components to render / unrender. We can provide a code snippet for this if Option 1 won't work, but I'd recommend Option 1, as it's the path of least resistance.
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,804 Points 20k badge 2x thumb
I've the same requirement but I've got just one table where the lookup is to itself. So Roll-up summary. Could I have that code snippet?
Photo of Peter Bender

Peter Bender, Champion

  • 6,266 Points 5k badge 2x thumb
And I need to show a message when the number of child records is less than what is expected, which is based on a value on the parent record, and I can't use a roll-up summary because this is to manage/count daily attendance records.
Photo of Ross James

Ross James

  • 490 Points 250 badge 2x thumb
Thanks Zach! Will try for option 1 for now.
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,148 Points 20k badge 2x thumb
Note.  As of the Superbank release it is now possible to specify rendering conditions based on number of rows in a model.  If rows = 0 show component A,  If rows=1 show component B, if rows = 2 show component C etc.