How could I show records with its most recent creadtedly child record in a table together

  • 1
  • Question
  • Updated 1 year ago
  • Answered
Is there any way to show the Most recently created child record with its parent record together.
I'm not able to retrieve the children information If I use the Parent as the table model.
However, if I use the child model for this table. Although I can lookup back to its parent record. But in this table, I have no way to filtered out the most recent child record.
Any idea to achieve this?


Photo of Poc

Poc

  • 496 Points 250 badge 2x thumb

Posted 1 year ago

  • 1
Photo of Jerry

Jerry

  • 1,150 Points 1k badge 2x thumb
Off the top of my head I'd say use two models. An aggregate model of the children grouped by parent and ordered by created date, and then another model of the children with all details where their Id is present in the aggregate model
Photo of Chandra V

Chandra V, Champion

  • 6,966 Points 5k badge 2x thumb
Here's how you can do it:

1. Create a model for your parent
2. In the field picker, select "Child Relationships".  Find your child object and select it.
3. Your child object will now show up in your field list (on the model).  Click it - then you can set some properties.
4. Select "CreatedDate" on your child object. We'll use this to get the most recently created child.  Select any other fields you want to show (looks like you want to show ChildStatus, so select that.)
5.  While clicked on the Child fields, select Properties.  Set the record limit to 1 (so you only get one record) and the Ordered By field to CreatedDate DESC so you get the one most recently created.



6.  Now create your table based on your Parent model.  From the model tree up top, drag that child relationship field to your table.  then you display fields using the Template merge syntax.


I build an example page using Accounts as the parent, and Contacts as the child.  So this table shows the most recently created Contact.

Here's the xml so you can see how I did it:


<skuidpage unsavedchangeswarning="yes" personalizationmode="server" showsidebar="true" useviewportmeta="true" showheader="true">
    <models>
        <model id="accounts" limit="20" query="true" createrowifnonefound="false" datasource="salesforce" type="" sobject="Account">
            <fields>
                <field id="Name"/>
                <field id="Id"/>
                <field id="Contacts" type="childRelationship" limit="1" orderby="CreatedDate DESC">
                    <conditions/>
                    <fields>
                        <field id="CreatedDate"/>
                        <field id="Name"/>
                    </fields>
                </field>
            </fields>
            <conditions/>
            <actions/>
        </model>
    </models>
    <components>
        <skootable showconditions="true" showsavecancel="true" showerrorsinline="true" searchmethod="server" searchbox="true" showexportbuttons="false" pagesize="10" createrecords="true" model="accounts" buttonposition="" mode="read" allowcolumnreordering="true" uniqueid="sk-3q_Qo2-128">
            <fields>
                <field id="Name" hideable="true" uniqueid="fi-3q_Shg-141"/>
                <field id="Contacts" type="CHILDREL" limit="100" hideable="true" uniqueid="fi-3q_Vxm-150" valuehalign="">
                    <label>Contacts</label>
                    <template>{{Name}}</template>
                </field>
            </fields>
            <rowactions>
                <action type="edit"/>
                <action type="delete"/>
            </rowactions>
            <massactions usefirstitemasdefault="true">
                <action type="massupdate"/>
                <action type="massdelete"/>
            </massactions>
            <views>
                <view type="standard"/>
            </views>
        </skootable>
    </components>
    <resources>
        <labels/>
        <javascript/>
        <css/>
    </resources>
    <styles>
        <styleitem type="background" bgtype="none"/>
    </styles>
</skuidpage>
Photo of Poc

Poc

  • 496 Points 250 badge 2x thumb
Groovy!
Appreciate your helpful answer.
One more question, it seems your solution only works for 1 child record.
Is it possible to make it work for multiple children records as the below image?
Thanks so much.

Photo of Bill McCullough

Bill McCullough, Champion

  • 12,426 Points 10k badge 2x thumb
Poc,

Is there a requirement to show the Child records in 2 columns?  The easiest approach is to show 2 records in the same Child record column.  Just change the record limit from 1 to 2.  You can add the date field to differentiate the entries.

If you must show the child records in 2 columns, you'll need a custom render for the second column.

Thanks,

Bill
Photo of Poc

Poc

  • 496 Points 250 badge 2x thumb
Any example or documentation can refer to the custom render you mentioned? Thanks