Salesforce Interview Questions & Answers Book is now available!

Grab Now

LWC

Navigate a user to a record page in edit mode in LWC

Let's look at how to Navigate a user to a record page in edit mode in LWC.

By Teja, ex-Salesforce engineer · Updated April 15, 2021 · 1 min read

In case you are interested in navigating an user to the standard edit form on click of a button (not using quick actions) then we can use NavigationMixin

In a way, this is similar to e.force:editRecord in Aura

Here is the snippet!

  • We are importing NavigationMixin from lightning/navigation
  • We are providing a config object to this[NavigationMixin.Navigate]
  • The config object is going to have information about the destination. The key is providing edit for the key actionName
import { LightningElement } from "lwc";

import { NavigationMixin } from "lightning/navigation";

export default class ExploreNavigation extends NavigationMixin(
  LightningElement
) {
  handleNavigate() {
    const config = {
      type: "standard__recordPage",
      attributes: {
        recordId: "00QXXXXXXXXXXlEAJ",
        objectApiName: "Lead",
        actionName: "edit"
      }
    };
    this[NavigationMixin.Navigate](config);
  }
}

Using NavigationMixin in LWC to open a record in edit mode

Hope this helps!

Learn it by building it

Every course, every code repository, the discussion group and certificates of completion — one subscription.

Keep me in the loop!

Email me when a new episode is published (promise, I will not spam you)

You're signing up to receive emails from Salesforce Casts