I am trying to access the value of a child object from an embedded query in a given lightning component. I am unable to assign the "checked" attribute to the checkbox component based on the nested query result. Is this just not possible in Lightning or am I missing something? I am pretty new to salesforce, but I haven't come across any post that deals with such a situation.

<aura:iteration items="{!v.NestedQueryResultList}" var ="item">
                        <lightning:input type ="checkbox" label ="{!item.Name}" name="{!item.Id}" checked="{!item.ObjectA_ObjectB__r.SomeBooleanValue__c}" onchange="{!c.handleChange}"/>

The variable of interest here is -


I am loading the NestedQueryResult object from the doInit() initializer based on the Nested Soql Query, as below -

SELECT Id, Name,
            (SELECT id,SomeBooleanValue__c
             FROM ObjectA_ObjectB__r WHERE ObjectA__c = :givenId) 
FROM ObjectB__c

The Relationship between the objects is as follows -

(Master)Object_A ----> (Child)ObjectA_ObjectB

(Master)Object_B ----> (Child)ObjectA_ObjectB

Basically ObjectA_ObjectB is a link between ObjectA and ObjectB.

1 Answer 1


You have to iterate over the children. This means you'll have a nested iteration.

<aura:iteration items="{!v.NestedQueryResultList}" var ="item">
  <aura:iteration items="{!item.ObjectA_ObjectB__r}" var="child">
    <lightning:input type ="checkbox" label ="{!child.Name}" name="{!child.Id}" checked="{!child.SomeBooleanValue__c}" onchange="{!c.handleChange}"/>
  • Thanks for the input. The issue is I need the name from the Master, not the child. Is it possible to access the "item" variable in the nested iteration? Oct 22, 2018 at 23:49
  • @A.WaliJr. Yes, you can still reference "item" inside of the "child" iteration.
    – sfdcfox
    Oct 23, 2018 at 0:00
  • Your workaround works. However, I need to add the checkbox even if item.ObjectA_ObjectB__r is null . Doing as you suggested means I end up losing some checkboxes which need to be added there. Oct 23, 2018 at 0:02
  • @A.WaliJr. you may need to reconsider your design, then. This isn't a "workaround", it's how nested objects work. A list needs to be iterated over, and a subquery is always a list.
    – sfdcfox
    Oct 23, 2018 at 0:03
  • Your answer definitely pointed me in the right direction. I really appreciate the help. Thanks. Oct 23, 2018 at 0:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.