My component is in the record page of MyObj__c . MyObj__c has a master detail with Account I tried to navigate from MyObj__c to the account assorted bu I always get an error
Error : {"status":500,"body":{"message":"Value provided is invalid for action parameter 'MyId2' of type 'Id'"},"headers":{},"ok":false,"statusText":"Server Error","errorType":"fetchResponse"}
=> Apex
@AuraEnabled(cacheable=true)
public static Id Class2(Id MyId2) {
Id account = [SELECT Station__c FROM MyObj__c WHERE Id =:MyId2 LIMIT 1]Station__c;
return account;
}
=> HTML
<template>
<div class="slds-box slds-theme_shade">
<lightning-button label="Back to the station" onclick={navigateToAccountPage}> </lightning-button>
</div>
</template>
=> JS
import { LightningElement, api , wire, track } from 'lwc';
import Class2 from '@salesforce/apex/MyClass.Class2';
import { NavigationMixin } from "lightning/navigation";
export default class RedirectToStation extends NavigationMixin (LightningElement) {
@api recordId ;
@track MyId2;
navigateToAccountPage() {
Class2({ MyId2: '$recordId' }).then(data => {
if (data)
{
this[NavigationMixin.Navigate]({
type: 'standard__recordPage',
attributes: {
recordId : data.Id,
objectApiName: 'Account',
actionName: 'view'
} });
}
}).catch(error => {
console.log('Error : ' + JSON.stringify(error));
})
}
}