I have a wizard on case object. The idea is to help agents to fill up the necessary data. however, I have trouble to show parent field (i.e Account.Name) in LWC HTML file.

Here is my code


public with sharing class CaseWizardController {
    public static Case getCase(Id caseId){
        return [SELECT Id, CaseNumber, Origin, Unit__c, Country__c, RecordType.Name, ContactId, Contact.Name, AccountId, Account.Name FROM Case WHERE Id =:caseId LIMIT 1];


import { LightningElement, track, api, wire } from 'lwc';
import getCaseDetails from '@salesforce/apex/CaseWizardController.getCase';
import updateCase from '@salesforce/apex/CaseWizardController.updateCase';
import { refreshApex } from '@salesforce/apex';

export default class CaseWizard extends LightningElement {
    //pagination variables
    @track page = 1; //current page
    totalPages = 5; //total page

    @track error;

    @api recordId; //current caseId
    @api wiredCase;
    @api realCase;
    @track accountName;
    @track contactName;

    @wire(getCaseDetails, { caseId: '$recordId' })
    getCaseDetails(resp) {
        this.wiredCase = resp;
        this.realCase = { ... this.wiredCase.data };
        this.accountName = this.realCase.Account.Name; //tried this but it isn't working
        this.contactName = this.realCase.Contact.Name; //tried this but it isn't working


        <h2 slot="title">
            <lightning-icon icon-name="custom:custom9" size="small"></lightning-icon>
            &nbsp; Case Wizard
        <!--Case Information-->
        <template if:true={realCase}>
            <template if:true={firstPage}>
                <div class="slds-m-around_medium">
                    <h1 class="slds-text-heading_small">Requester</h1>
                <div class="slds-m-around_medium">
                    <lightning-input type="text" name="account" readonly label="Account" value={accountName}>
                    <lightning-input type="text" name="contact" readonly label="Contact" value={contactName}>
                    <lightning-input type="text" name="client" readonly label="Client" value={realCase.Client_Type__c}>
                    <lightning-input type="text" name="clientSubType" readonly label="Client Sub Type"
                    <lightning-input type="text" name="relatedName" label="Related Name" value={realCase.Complainer_Name__c}></lightning-input>
                    <lightning-input type="text" name="relatedEmail" label="Related Email" value={realCase.Complainer_Email__c}></lightning-input>
                    <lightning-input type="text" name="relatedPhone" label="Related Phone" value={realCase.Go_Food_Complainer_Phone__c}></lightning-input>
        <div slot="footer">
                    <lightning-button label="Previous" icon-name="utility:chevronleft" onclick={handlePrevious}
                <lightning-layout-item flexibility="grow"></lightning-layout-item>
                    <lightning-button label="Next" icon-name="utility:chevronright" icon-position="right"
                        onclick={handleNext} disabled={fifthPage}></lightning-button>
                    <lightning-button label="Submit" variant="brand" title="Submit action" icon-position="right"
                        onclick={handleSubmit} disabled={notFifthPage}></lightning-button>


1 Answer 1


[Wire service] always return object with properties data and error. Initially, it returns with both undefined and so if you dont put conditions then you will get errors as you cant access Name of undefined. You can implement as below:

@wire(getCaseDetails, { caseId: '$recordId' })
consList({ data, error }) {
    if (data) {
        this.realCase = { ...data };
        this.accountName = this.realCase.Account.Name; //tried this but it isn't working
    } else if (error) {
        // handle error
        console.error('ERROR => ', error);
  • Hi @salesforce-sas, thanks man for pointing out, I missed that! Sep 4, 2019 at 13:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .