0

I want to navigate to the related list of accounts with click of the button in LWC.

But when I click on the button I am getting the below error :

Error in $A.getCallback() [Cannot read property 'errors' of undefined]

NavigatetoRelatedlist.js

import { LightningElement, api } from 'lwc';
import {NavigationMixin} from 'lightning/navigation';

export default class navigateToRelatedList extends NavigationMixin(LightningElement) {
    @api recordId;
    navigateRelatedListView() {
        this[NavigationMixin.Navigate]({
            type: 'standard__recordRelationshipPage',
            attributes: {
                recordId: this.recordId,
                objectApiName: 'Account',
                relationshipApiName: 'Contacts',
                actionName: 'view'
            },
        });
    }
}

NavigatetoRelatedlistHtml

<template>
    <lightning-card title="Navigate to Related List View">
        <lightning-button variant="brand" label="Related List View"
        onclick={navigateRelatedListView}></lightning-button>

    </lightning-card>
</template>

Can you help me why i am getting the above error . Do i need to pass recordID

7
  • The code looks fine to me, it could be another component(aura component)/customization around this object which must be conflicting.Give a try in fresh dev/trial org with same code and check, it should work. Jun 10, 2021 at 13:25
  • @ShivankurNaikwade i tried in new dev org but still seeing the same error
    – SFDCSai
    Jun 10, 2021 at 16:29
  • is there more code to this component? Any references to errors within your component in some error handling? Jun 10, 2021 at 19:12
  • @KrisGoncalves yes this is only the code i have checked for error Handling in the [link text] (salesforce.stackexchange.com/questions/297165/… ) this post and observed that NavigationMixin's Navigate API does not return a promise.
    – SFDCSai
    Jun 11, 2021 at 6:56
  • @vijayUmmeda, It looks like you have added this button on Home Page and its not having value in 'this.recordId' And so is the reason the error.I was able to reproduce this on home page at my end. If you add the same button on account page, this should work smoothly. Jun 11, 2021 at 7:20

1 Answer 1

1

It looks like you have added this button on Home Page and it's not having any value in 'this.recordId' basically, And so is the reason the error.I was able to reproduce this on home page at my end. If you add the same button on account page, this should work smoothly.

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.