You need to sign in to do that
Don't have an account?
Tom Dawson
Accessing attributes through related object
Hi All
I'm trying to access field values from an object related to the initial one in the call. Our relationship is as follows:
Contact --> Post Fulfillment --> Post
I am trying to use an iteration to get values from Post when the initial call is to Contact. See code below:
Apex:
I am able to access both Name and Phone from the contact. I can also see from the Chrome inspector that the field values for Location are coming through, I just cannot access them.
As you can see i have tried
Any help would be great.
Thanks
Tom
I'm trying to access field values from an object related to the initial one in the call. Our relationship is as follows:
Contact --> Post Fulfillment --> Post
I am trying to use an iteration to get values from Post when the initial call is to Contact. See code below:
Apex:
@AuraEnabled public static List<Contact> getHSList(){ List<Contact> myHSList = new List<Contact>(); myHSList = [Select Id, Name, Fire_Warden__c, Phone, (SELECT id, Post__c,Post__r.Area__c, Post__r.Floor__c, Post__r.Section__c FROM Contact.Post_Fulfillments__r) From Contact Where Fire_Warden__c = true]; return myHSList; }Controller
({ onInit : function(component, event, helper) { console.log('onInit'); var action = component.get("c.getHSList"); action.setCallback(this, function(a) { var HandSData = a.getReturnValue(); console.log(HandSData); component.set("v.contactList",HandSData); console.log(HandSData.length); }); $A.enqueueAction(action); } })Component
<aura:Iteration items="{!v.contactList}" var="con" > <tr class="slds-hint-parent"> <th data-label="Name" scope="row"> <div class="slds-truncate" title="Cloudhub">{!con.Name}</div> </th> <td data-label="Phone"> <div class="slds-truncate" title="Cloudhub">{!con.Phone}</div> </td> <td data-label="Close Date"> <div class="slds-truncate" title="4/14/2015">{!con.Post_Fulfillments__r.Post__r.Floor__c} place</div> </td> </tr> </aura:Iteration>
I am able to access both Name and Phone from the contact. I can also see from the Chrome inspector that the field values for Location are coming through, I just cannot access them.
As you can see i have tried
{!con.Post_Fulfillments__r.Post__r.Floor__c}But it doesnt seem to work.
Any help would be great.
Thanks
Tom
We you can't do this, because con.Post_Fulfillments__r this one is an another list.
Incorrect
Correct
Or we can use another <aura:Iteration> inside the <aura:Iteration> like this.
Regards,
Soyab
All Answers
We you can't do this, because con.Post_Fulfillments__r this one is an another list.
Incorrect
Correct
Or we can use another <aura:Iteration> inside the <aura:Iteration> like this.
Regards,
Soyab
Fantastic - working great now, thanks!!
Tom