0

First time with Aura components, having a hard time understanding them.

I'm trying to write a simple component that shows some related object fields. I know there's a standard one provided by Salesforce for that, but I need to write my own.

What I want to show is some related fields which are two levels up. The component would be placed on the SocialPost object and will retrieve fields from the Contact Object.

The two are related in the following way: Contact --> Social Persona --> Social Post.

So I have a lookup relationship on SocialPost to Persona, and persona has a lookup relationship to Contact (called Parent).

For a better understanding, the Query SELECT Persona.Parent.Name from SocialPost would return the Contact Name.

Now, I am having a hard time understanding how to display such field on my custom component. Here's what I tried:

<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId" access="global">
    <aura:attribute name="recordId" type="Id"/>
    <aura:attribute name="post" type="SocialPost"/>
  
    
    <force:recordData aura:id="personaRecord"
                      recordId="{!v.recordId}"
                      targetFields="Persona.Parent.Name"
                      layoutType="FULL"/>

     <lightning:recordViewForm recordId="{!v.recordId}" objectApiName="SocialPost">
        <lightning:card title="Contact" >
            <p class="slds-p-horizontal_small">
                <div class="slds-grid">
                    <div class="slds-col slds-size_1-of-2">
                        <label class="slds-form-element__label" for="form-element-01">Name</label>
                        <lightning:outputField variant="label-hidden" fieldName="Persona__r.Parent__r.Name" /> 
                        
                    </div>
                </div>
            </p>
        </lightning:card>        
    </lightning:recordViewForm>
    
</aura:component>

I probably wrote some horror code, I know, but as I said, I'm having a hard time understanding how to implement this. Could anyone help me understand how to make this?

Thanks!

0
<lightning:outputField variant="label-hidden" fieldName="Persona__r.Parent__r.Name" />

Here fieldName value is invalid. It can only take fields of the SocialPost.

Also reference: Use lightning:recordViewForm to show related record data

You can use force:recordData to fetch parent fields and display them in a custom layout.

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.