Model condition based on child records

  • 1
  • Question
  • Updated 3 years ago
  • Answered
I'm trying to load only ParentObject__c records where ChildObject__r.records != null. Is that possible? I figured out I could hack the XML to do this with render conditions, but when I tried that with the Model conditions it wouldn't work, it gave an error that it couldn't recognize the field ChildObect__r.records (or ChildObect__r.records.0.Id etc, tried a few variations).

Is it possible to hack the XML this way, or do I just need to load all the possible Child Records in a new model and then use that as a condition for loading my parent model?
Photo of Jack Sanford

Jack Sanford, Champion

  • 8,322 Points 5k badge 2x thumb

Posted 3 years ago

  • 1
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
Are the child records master-detailed? If so, use rollup to count them. Otherwise you can use DLRS to do the same thing. 
https://github.com/afawcett/declarative-lookup-rollup-summaries
Photo of Jack Sanford

Jack Sanford, Champion

  • 8,322 Points 5k badge 2x thumb
Sometimes the simplest answer is the best. Actually most times I guess. That worked. Thanks Pat!
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
This is a perfect use case for a "Result of Subquery" Condition. Result of Subquery Conditions are ideal for finding parent records with/without child / related records, optionally filtered by "Subconditions". For instance if you wanted to find Account records with child Contacts, you would create a "Result of Subquery Condition" on your Contacts Model like this:

Field: Account Id
Operator: in
Content: Result of Subquery
 - Join Object: Contact
 - Join Field: AccountId

This will show just Accounts that have Contacts.
Photo of Jack Sanford

Jack Sanford, Champion

  • 8,322 Points 5k badge 2x thumb
AHA! I knew there was a way to do it. Thanks Zach! That worked perfect too. 
Photo of Jack Sanford

Jack Sanford, Champion

  • 8,322 Points 5k badge 2x thumb
Ok, so how do the subconditions work? I'm trying to do Completed__c != Yes, but I keep getting errors. 

If I do Completed__c !='Yes' it outputs as Completed__c !=\'Yes'\ and says \ is not a viable character. 

If I put Completed__c !=Yes it wants a colon, then if I add the colon it says Yes it not a variable.

If I put Completed__c !="Yes" it renders the same but says that " is not a viable character. 

Any ideas?
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
What kind of field is "Completed__c" ?
Photo of Jack Sanford

Jack Sanford, Champion

  • 8,322 Points 5k badge 2x thumb
Nevermind, I was messing things up - same problem as this: https://community.skuidify.com/skuid/topics/subquery-error-using-like-condition

I was trying to put my subcondition in the logic field. 
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
Ah, that makes sense. Apparently this is a common source of confusion...