Summarize a Child Relationship of a Parent object

  • 1
  • Question
  • Updated 2 years ago
  • Answered
Let's play - Is It Possible!!


Is it possible to summarize a child relationship of a parent object?

Use case using native objects:
Accounts, Contacts, and Cases


When I am looking at a table of Cases, can I display a list of the Contacts from that account in the table?

I attached a low tech example.


Note: I know that the option to do this isn't available through the Page Builder (fields --> child relationships), so I would expect it would be something that I'd do through the XML



Thanks! 
Photo of Griffin Brown

Griffin Brown

  • 2,796 Points 2k badge 2x thumb
  • giddy

Posted 2 years ago

  • 1
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,774 Points 20k badge 2x thumb
You can use DLRS to Concatenate the Names from the Contact records into the Account record. You alternatively Concatenate the Contacts Ids and create a custom field renderer and model to make them clickable.
Photo of Griffin Brown

Griffin Brown

  • 2,796 Points 2k badge 2x thumb
I was hoping to find a lighter weight alternative to DLRS, but it's currently how I circumvent the problem. Am I SOL otherwise?

The custom field renderer idea is a killer idea!
Photo of Griffin Brown

Griffin Brown

  • 2,796 Points 2k badge 2x thumb
Is there a way to make something like this work:

1. XML built by the Page Builder:
<field id="ActivityHistories" type="childRelationship" limit="10"/>

2. Tweak it to something like this:
<field id="Account__r.Contacts" type="childRelationship" limit="10"/>
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,774 Points 20k badge 2x thumb
Unfortunately not. Skuid models are limited to SOQL capabilities and this ins't possible. Think you're stuck with building a custom field rendered for this requirement.
Photo of Andrey

Andrey

  • 80 Points 75 badge 2x thumb
Unless, the relationship between Account and Contact exists.
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,774 Points 20k badge 2x thumb
It does, but I'm not certain that a Accounts' Contacts can be retrieved when the SOQL is "Select Id, Account FROM Case".

Where in this SOQL can Contacts related to the Account be pulled in?
Photo of Andrey

Andrey

  • 80 Points 75 badge 2x thumb
As simple as querying the reference name and the field you want:

Let's say there's a lookup relationship between Account and Contact called Contact__c, so:

[SELECT Id, Contact__r.Name FROM Account WHERE ID = 'something' ];

The Contact__r lets you access Contact directly to the record it is related to. 
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,774 Points 20k badge 2x thumb
er ... uh ... the model is based on Case. So the SOQL is "FROM Case".
Photo of Andrey

Andrey

  • 80 Points 75 badge 2x thumb
Ahhh, I'd just go through the good ol' references in Salesforce (adding a custom relationship from Account to Contact - 1:m). That, or write the table down with JS :)

No idea how to do it on the XML straight tho.
(Edited)
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,026 Points 20k badge 2x thumb
Ok.  Here is the way.  100% declarative.  No XML, No Formula Fields, No Javascrpt,  No APEX..

Just use multiple models,  and UI only relationships between them. 

(honestly guys, this came to me as I was lying awake last night...  that's just how my life is...)

Details....  Create two models. 
1. Account model 
- This one has to be first in model order
- Add contacts child relationships

2. Cases model.
- Make sure the AccoundId is included in this model
- Create a UI Only field on this model that uses the "ModelLookup" function.  Lookup the child relationship on the Accounts model.  The syntax in my case looked like this: 

MODEL_LOOKUP('Accounts','Contacts','Id',{{AccountId}})

3. Build a table on the Cases model with your case subject, account name and whatever else you want. 

4. Add a template to the table where you retrieve data from the contacts object record retrieved from the Account model. You can't just drag the UI Only field into your table because it just has an object in it (You get "object:object" in your fields.  But you can use a template to dig down into the object and show its data.  The template syntax I used was: 

{{#AccountContacts.records}}{{Name}}
{{/AccountContacts.records}}


CAVEAT:  I'm not sure this solution scales well.  It requires you to have all the accounts that are going to be in model 2 pre-loaded in model 1.  If you have hundreds of accounts - that might be fine.  But if you have thousands of accounts it will be problematic.  You might be able to use the cross model filter synching tools that Pat Vachon introduced last year, or something else...   But that's just word to the wise. 

Here is a picture:

 

(note - you can see the two cases for salesforce.com.... Proving that this model is built on the cases object. )

Here is the xml for my page: 

<skuidpage unsavedchangeswarning="yes" personalizationmode="server" showsidebar="true" showheader="true">
<models>
<model id="Accounts" limit="20" query="true" createrowifnonefound="false" adapter="salesforce" type="" sobject="Account">
<fields>
<field id="Name"/>
<field id="Id"/>
<field id="Contacts" type="childRelationship" limit="10">
<fields>
<field id="Name"/>
</fields>
</field>
</fields>
<conditions/>
<actions/>
</model>
<model id="Cases" limit="20" query="true" createrowifnonefound="false" adapter="salesforce" type="" sobject="Case" doclone="">
<fields>
<field id="Subject"/>
<field id="AccountId"/>
<field id="Account.Name"/>
<field id="AccountContacts" uionly="true" displaytype="FORMULA" readonly="true" returntype="TEXT">
<formula>MODEL_LOOKUP('Accounts','Contacts','Id',{{AccountId}})</formula>
</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="Cases" buttonposition="" mode="read" uniqueid="sk-nXhXn-357">
<fields>
<field id="Subject" valuehalign="" type=""/>
<field id="AccountId" valuehalign="" type=""/>
<field type="COMBO" valuehalign="">
<label>Account Contacts</label>
<template>{{#AccountContacts.records}}{{Name}}&lt;br&gt;{{/AccountContacts.records}}</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>

(Edited)
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,774 Points 20k badge 2x thumb
This is super cool. Haven't seen this formula yet. Model_Lookup is a hidden gem.

Kinda like Model cloning. Hidden and under utilized.
Photo of Griffin Brown

Griffin Brown

  • 2,796 Points 2k badge 2x thumb
Totally under utilized.

This is brilliant!