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
Melissa BunchMelissa Bunch 

Display Account Hierarchy in Lightning Component on the Account Lightning Record Page

Hello!

I would like to display the actual Account Hierarchy within a Lightning Component on the Lightning Record Page for my Accounts.

I was able to find code to add a Lightning Component that links to the hierarchy, but I want to actually display the hierarchy instead.

Does anyone know how to do this? Below is a screenshot of the code I found and how it looks. Maybe I can edit the existing code to display the hierarchy?

COMPONENT
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId">
    <div class="slds-section slds-is-open">
        <h3 class="slds-section__title">
            <button aria-controls="expando-unique-id" aria-expanded="true" class="slds-button slds-section__title-action">
                <lightning:icon iconName="utility:switch" alternativeText="" size="x-small" />
                <span class="slds-truncate" title="Section Title"> &nbsp;Account Hierarchy Link</span>
            </button>
        </h3>
        <div aria-hidden="false" class="slds-section__content" id="expando-unique-id">
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a onclick="{!c.navigateToAccountHierarchy}">View Account Hierarchy</a>
        </div>
    </div>
</aura:component>

CONTROLLER

({
    navigateToAccountHierarchy: function(cmp, event, helper) {
        var acctId = cmp.get('v.recordId');
        var evt = $A.get("e.force:navigateToComponent");
        evt.setParams({
            componentDef: "sfa:hierarchyFullView",
            componentAttributes: {
                recordId: acctId,
                sObjectName: "Account"
            }
        });
        evt.fire();
    }
})

RESULT
User-added image
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Melissa,

Please find the code from the below link. I implemented the same and it is showing us the account hirerachy when we onclick the link as expected.

User-added image
https://sfdx.pro/articles/account-hierarchy-salesforce-lightning/

If this solution helps, Please mark it as best answer.

Thanks,