Get parent record fields using getRecord uiRecordApi in lwc

Telegram logo Join our Telegram Channel

Hi Trailblazers! In this post, we will discuss how we can query parent record fields using getRecord method from the uiRecordApi library of Lightning web components.

For this, we are going to use the below methods from the uiRecordApi

  • getRecord: method to get the sObject record
  • getFieldValue: method to get the field value from the getRecord result.

For this demo, we are going to demonstrate using a Contact record. In this example, we are going to fetch the Account Name, and Account's Parent's name from the Contact record.

First, you need to import these fields from the Salesforce Schema. Like below

import ACCOUNT_NAME from "@salesforce/schema/Contact.Account.Name";
import GRAND_PARENT_ACCOUNT from "@salesforce/schema/Contact.Account.Parent.Name";
import CONTACT_NAME from "@salesforce/schema/Contact.Name";

So in the above example, we have imported standard objects record, for custom objects use the below syntax.

import ACCOUNT_NAME from "@salesforce/schema/Custom_Object__c.Parent__r.Name";
import GRAND_PARENT_ACCOUNT from "@salesforce/schema/Custom_Object__c.Parent__r.Grand_Parent__r.Name";

Also, you need to import the getRecord method like below.

import { getRecord, getFieldValue } from "lightning/uiRecordApi";

Second thing, you need to wire the getRecord and getFieldValue methods that we imported in the last step.

The Final Code

I have created a simple component named showParentFields


import { LightningElement, api, wire } from "lwc";
import { getRecord, getFieldValue } from "lightning/uiRecordApi";
import ACCOUNT_NAME from "@salesforce/schema/Contact.Account.Name";
import GRAND_PARENT_ACCOUNT from "@salesforce/schema/Contact.Account.Parent.Name";
import CONTACT_NAME from "@salesforce/schema/Contact.Name";

export default class ShowParentFields extends LightningElement {
	@api recordId;

	@wire(getRecord, {
		recordId: "$recordId",

	get contactName() {
		return getFieldValue(, CONTACT_NAME);

	get parentAccountName() {
		return getFieldValue(, ACCOUNT_NAME);

	get grandParentAccountName() {
		return getFieldValue(, GRAND_PARENT_ACCOUNT);


    <lightning-card title="Get Parent fields using uiRecordApi Demo">
        <div class="slds-var-p-around_medium">
            <h1 class="slds-text-body_regular"><b>Contact Name:</b> {contactName}</h1>
            <h1 class="slds-text-body_regular"><b>Parent Account Name:</b> {parentAccountName}</h1>
            <h1 class="slds-text-body_regular"><b>Grand Parent Account Name:</b> {grandParentAccountName}</h1>


<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="">

The final output


No comments :
Post a Comment

Hi there, comments on this site are moderated, you might need to wait until your comment is published. Spam and promotions will be deleted. Sorry for the inconvenience but we have moderated the comments for the safety of this website users. If you have any concern, or if you are not able to comment for some reason, email us at