function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MindesMindes 

How to get parent.parent field input

Hello,

I can't find access to the second level account record.
On the case record in the lightning component we need to pull Account field and Parent Account field. In first level Account, field is set properly, but not for the second level parent Account. Example below, and input that not working is underlined.
 
({
    initialize: function(component, event, helper) {
        var caseId = component.get("v.recordId");
        var action = component.get("c.getAccountInformation");
         action.setParams({
             caseId
         });
        action.setCallback(this, function(a){
             var rtnValue = a.getReturnValue();
             var state = a.getState();
             if (state === 'SUCCESS'){
                 component.set("v.AM", rtnValue.Account.Account_Manager__c);
                 component.set("v.ParentAM", rtnValue.Account.ParentId.Account_Manager__c);

              } else {
                  console.log(a.getReturnValue());
             }
          });

Please advice,
 
vishal-negandhivishal-negandhi

In your apex controller method "getAccountInformation", have you already added this field in the query? 

Can you also share your apex controller please

MindesMindes
Component:
 
<aura:component
        implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction"
        access="global"
        controller="CTRL_VIPClient">
    <aura:handler name="render" value="{!this}" action="{!c.onRender}"/>
    <aura:handler name="init" value="{!this}" action="{!c.initialize}"/>
    <aura:attribute name="recordId" type="Id"/>
    <aura:attribute name="AM" type="String"/>
    <aura:attribute name="ParentAM" type="String"/>

    <lightning:card iconName="custom:custom53" title="VIP Client Information">
        <div class="slds-p-left_large slds-p-right_medium">

            <span class="slds-form-element__label">Account Manager Name</span>
            <div class="slds-form-element__control slds-m-bottom_medium">
                <div class="slds-form-element__static">
                    <p>{!v.AM}</p>
                </div>
            </div>
            
            <span class="slds-form-element__label">Parent Acccount Manager</span>
            <div class="slds-form-element__control slds-m-bottom_medium">
                <div class="slds-form-element__static">
                    <p>{!v.ParentAM}</p>
                </div>
            </div>
            
        </div>
    </lightning:card>
    <section role="dialog" tabindex="-1" aria-labelledby="modal-heading-01" aria-modal="true" aura:id="Modalbox2"
             aria-describedby="modal-content-id-1" class="slds-modal">
        <div class="slds-modal__container">
            <header class="slds-modal__header">
                <button class="slds-button slds-button_icon slds-modal__close slds-button_icon" title="Close">
                    <lightning:buttonIcon alternativeText="Close" iconName="utility:close" onclick="{!c.closeModal}"/>
                    <span class="slds-assistive-text">Close</span>
                </button>
                <h2 id="modal-heading-01" class="slds-modal__title slds-hyphenate">VIP Client Alert</h2>
            </header>
            <div class="slds-modal__content slds-p-around_medium" id="modal-content-id-1">
                <lightning:layoutItem size="12" class="" padding="around-small">
                    <aura:unescapedHtml value="{!$Label.c.VIP_Account_Modal_Content}"/>
                </lightning:layoutItem>
                <lightning:layoutItem size="12" class="" padding="around-small">
                    <span class="slds-form-element__label">Account Manager Name</span>
                    <div class="slds-form-element__control slds-m-bottom_medium">
                        <div class="slds-form-element__static">
                            <p>{!v.AM}</p>
                        </div>
                    </div>
                </lightning:layoutItem>
                <lightning:layoutItem size="12" class="" padding="around-small">
                    <span class="slds-form-element__label">Parent Account Manager</span>
                    <div class="slds-form-element__control slds-m-bottom_medium">
                        <div class="slds-form-element__static">
                            <p>{!v.ParentAM}</p>
                        </div>
                    </div>
                </lightning:layoutItem>                    

                </lightning:layoutItem>
            </div>
            <footer class="slds-modal__footer">
                <button class="slds-button slds-button_neutral" onclick="{!c.closeModal}">Close</button>
            </footer>
        </div>
    </section>
    <div class="slds-backdrop" aura:id="Modalbackdrop2"></div>
</aura:component>

Controller:
 
({
    initialize: function(component, event, helper) {
        var caseId = component.get("v.recordId");
        console.log("were here");
        var action = component.get("c.getAccountInformation");
         action.setParams({
             caseId
         });
        action.setCallback(this, function(a){
             var rtnValue = a.getReturnValue();
             var state = a.getState();
             if (state === 'SUCCESS'){
                 component.set("v.AM", rtnValue.Account.Account_Manager_Name__c);
                 component.set("v.ParentAM", rtnValue.Account.ParentId.Account_Manager_Name__c);
              } else {
                  console.log(a.getReturnValue());
             }
          });
         
         $A.enqueueAction(action);
    },
    onRender: function(component, event, helper){
        var recordId = component.get('v.recordId');
        var windowLocation = window.location.href;
        if (!windowLocation.includes('lightning.force.com/flexipageEditor')){
           var a = component.get('c.openModal');
           $A.enqueueAction(a);
        }

    },
    closeModal: function (component, event, helper) {
            var cmpTarget = component.find('Modalbox2');
            var cmpBack = component.find('Modalbackdrop2');
            $A.util.removeClass(cmpBack, 'slds-backdrop--open');
            $A.util.removeClass(cmpTarget, 'slds-fade-in-open');
     },
    openModal: function (component, event, helper) {
        var cmpTarget = component.find('Modalbox2');
        var cmpBack = component.find('Modalbackdrop2');
        $A.util.addClass(cmpTarget, 'slds-fade-in-open');
        $A.util.addClass(cmpBack, 'slds-backdrop--open');
    }

})

 
vishal-negandhivishal-negandhi
Sorry, I meant the apex controller - CTRL_VIPClient
MindesMindes
public static Case findByIdWithAccountInformation(Id caseId)
    {
        Case aCase =
        [
                SELECT
                        Id,
                        AccountId,
                        Account.AM_Notes__c,
                        Account.Account_Manager_Name__c,
                        Account.Parent.Account_Manager_Name__c,
                        Account.Parent.Id
                        
                FROM
                        Case
                WHERE
                Id = :caseId
                AND AccountId != null
        ];
        return aCase;
    }

i have tried to use as Account.ParentId.* it's not working. 
vishal-negandhivishal-negandhi
Your controller is correct and you're also querying the field, you need to change your component code a bit
This has incorrect field name "ParentId"
component.set("v.ParentAM", rtnValue.Account.ParentId.Account_Manager_Name__c);

should be Parent.field_name
component.set("v.ParentAM", rtnValue.Account.Parent.Account_Manager_Name__c);


This should fix your problem.