I'm trying to navigate to the contact record page from the account object details page.
The scenario is: In the Account object there are multiple contacts available. When I click on any of the contacts, it should open on the Contact object details page. I'm trying it by using Navigation mixin and by passing on the recordId, but it will open on account objects only.
Can any one try to guide me how to do this?!
js:
import { LightningElement, track, wire, api } from 'lwc';
import findContacts from '@salesforce/apex/GetContactController.getContacts';
import { NavigationMixin } from 'lightning/navigation';
const DELAY = 300;
export default class GetContactOnAccount extends NavigationMixin(LightningElement) {
@track searchKey = '';
@api recordId;
@wire(findContacts, { searchKey: '$searchKey' })
contacts;
navigateToNewContactPage() {
this[NavigationMixin.Navigate]({
type: 'standard__recordRelationshipPage',
attributes: {
recordId: this.recordId,
objectApiName: 'Account',
relationshipApiName: 'Contacts',
actionName: 'view'
},
});
}
//connectedCallback function is similar to init method in Lightning Components.
connectedCallback(){
this.searchKey = this.recordId;
}
}