function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ertyq MrskErtyq Mrsk 

Error Displaying When Clicking Custom Cancel Button in Salesforce LWC

In my LWC page, I created an Update form with both Update and Cancel buttons. This cancel button should redirect the user to the current record's detail page.

Update button works well and redirects back to the updated record detail page. But on cancel button, it navigates to a page displaying an error message:

User-added image

Following is the javascript portion of cancel function:
cancel() {
        
   this[NavigationMixin.Navigate]({
      type: "standard__objectPage",
        attributes: {
            recordId: this.recordId,  
            objectApiName: "Account",
            actionName: "view"
        }
   });
}
How can I fix this?

 
Best Answer chosen by Ertyq Mrsk
AnudeepAnudeep (Salesforce Developers) 
Can you change the type from "standard_objectPage" to "standard_recordPage" and let me If it makes any difference? I was referring to this blog post and this recommendation is coming from observing the sample code
 
@api recordId;
    // Navigate to New Account Page
    navigateToNewAccountPage() {
        this[NavigationMixin.Navigate]({
            type: 'standard__objectPage',
            attributes: {
                objectApiName: 'Account',
                actionName: 'new'
            },
        });
    }
 
// Navigate to View Account Page
    navigateToViewAccountPage() {
        this[NavigationMixin.Navigate]({
            type: 'standard__recordPage',
            attributes: {
                recordId: this.recordId,
                objectApiName: 'Account',
                actionName: 'view'
            },
        });
    }

Let me know if this helps. If it does, please close this query by marking it as solved so that it may help others in the community. Thank You!
 

All Answers

AnudeepAnudeep (Salesforce Developers) 
Can you change the type from "standard_objectPage" to "standard_recordPage" and let me If it makes any difference? I was referring to this blog post and this recommendation is coming from observing the sample code
 
@api recordId;
    // Navigate to New Account Page
    navigateToNewAccountPage() {
        this[NavigationMixin.Navigate]({
            type: 'standard__objectPage',
            attributes: {
                objectApiName: 'Account',
                actionName: 'new'
            },
        });
    }
 
// Navigate to View Account Page
    navigateToViewAccountPage() {
        this[NavigationMixin.Navigate]({
            type: 'standard__recordPage',
            attributes: {
                recordId: this.recordId,
                objectApiName: 'Account',
                actionName: 'view'
            },
        });
    }

Let me know if this helps. If it does, please close this query by marking it as solved so that it may help others in the community. Thank You!
 
This was selected as the best answer
Ertyq MrskErtyq Mrsk
@Anudeep I tried your suggestion, and it redirects back to the record page now. Thanks a lot!