You need to sign in to do that
Don't have an account?
Priyanka Reddy 74
How to call Lightning Navigation function() from another function.
getRequest(){ Request({recordId : this.recordId}) .then(data => { alert('1'); this.newRecordId = data; }) .catch(error=>{ alert(error) }) this.navigateNext(); }
navigateNext() { alert('2'); this[NavigationMixin.Navigate]({ type: 'standard__recordPage', attributes: { recordId: this.newRecordId, actionName: 'view' } }); }
Hi All,
I want to call navigateNext() from getRequest() in LWC, In some cases, the page is navigating some times it is not.
I put 2 alert statements to understand flow For the first time when i call the getRequest() for the first time alert('2') which is in navigatinNext() and then alert('1') is getting printed, from the second time output is as alert('1') then alert('2');
Can someone help me where I went wrong?
Put your navigateNext method inside the Request promise solve block. Because apex imperative method is a one type of Asynchronous JS so it won't wait for the request call result instead it will execute the next line . so you have to call the navigateNext method inside the Request data block.
Thanks,
Maharajan.C
In your code you call navigate next function after the request is completed that does not matter what they get error or recordId in case of recordId maybe your code run but if the recordId not get or provide some kind of error also fire navigation which causes you a problem.
you check this code for your program this you have to declare the recordId variable
if you find this helpful mark it as the best answer.
thanks
Malika Pathak.