0

How can I perform a Boolean check as to whether or not the standard Salesforce Edit Record modal is open from a Lighting Web Component (LWC) in a Lightning Console App?

For Salesforce Console in Lightning Experience, I have created a Lightning Web Component (LWC) that can be viewed at a URL that has the following format:

https://example.lightning.force.com/lightning/n/Example_Component

In part of the code, I am opening up the standard Edit Record modal for a record using NavigationMixin.Navigate:

this[NavigationMixin.Navigate]({
  type: 'standard__recordPage',
  attributes: {
    actionName: 'edit',
    recordId: 'a00XXXXXXXXXXXXXXXX',
  },
});

Normally, when this is executed in an app that IS NOT a Lightning Console App, the URL of the page will change to something like this:

https://example.lightning.force.com/lightning/r/Example__c/a00XXXXXXXXXXXXXXXX/edit?backgroundContext=%2Flightning%2Fn%2FExample_Component&count=1

This is useful because we can use location.pathname to determine if the modal is still open:

if (location.pathname === '/lightning/n/Example_Component') {
  // The standard Edit Record modal IS NOT open ...
} else if (/^\/lightning\/r\/\w+\/([a-z\d]{15}|[a-z\d]{18})\/edit$/gi.test(location.pathname)) {
  // The standard Edit Record modal IS open ...
}

The problem with this approach is that in a Lightning Console App, the URL does not change when the standard Edit Record modal is open.

Standard Salesforce Edit Record Modal

Are there any ways to determine if the standard Salesforce Edit Record modal is active over a LWC from a Lightning Console App?

For example, would it be possible to use the $A or the Sfdc global objects to somehow gain more insight into whether or not the modal is open? Or is there some built-in feature for Lightning Web Components where this can be checked?

I am trying to avoid having to develop a custom edit form, if at all possible. Finding a solution that uses the standard Edit Record modal is strongly preferred.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.