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
Big EarsBig Ears 

POSSIBLE BUG - Lightning Experience - Edit override with nooverride option

We need a conditional override in Lightning Experience which may return a custom component/VF page or will return the standard edit behaviour. We've been investigating various options which each seem to have their own blockers/issues:

1) Rely on the VF overrides which exist in classic This has numerous issues with navigation on multi-screen overrides (meaningful retURL attributes are not available to the VF page controller, so all button presses would need to be re-developed to handle LEX)
Lightning Component which uses e.force:editRecord event This event can't have "nooverride=1" applied to it, so forces the Browser into an infinite loop, as the edit behaviour gets caught in its own override.

Here is the component controller:
 
({ 
    onInit : function(component, event, helper) { 
         /*CAUSES INFINITE LOOP IN OVERRIDE CONTEXT*/ 
        var editRecordEvent = $A.get("e.force:editRecord"); 
        editRecordEvent.setParams({ "recordId": component.get("v.recordId") }); 
        editRecordEvent.fire(); 
    } 
})

2) Lightning Component which uses lightning:navigation component This can have nooverride=1 applied, but opens the Edit modal with blank context underneath it, rather than on top of the existing context. This means that the user flow is broken (hitting cancel leaves the user on a blank page, hitting save breaks the user flow completely - pictures below (POTENTIAL BUG?))

Component
<aura:component implements="lightning:actionOverride,force:hasRecordId" access="global" >
    <lightning:Navigation aura:Id="navService" />
    <aura:handler name="init" value="{!this}" action="{!c.onInit}"/>
</aura:component>

Controller
({
    onInit : function(component, event, helper) {
        /*THIS OPENS THE MODAL IN A BLANK LIGHTNING EXPERIENCE PAGE, RATHER THAN IN THE CONTEXT OF THE CURRENT PAGE*/ 
        
        var nav = component.find("navService"); 
        var pageReference = { 
                                             "type": "standard__recordPage", 
                                             "attributes": {
                                                                  "recordId": component.get("v.recordId"), 
                                                                  "actionName": "edit"
                                                                }, 
                                             state: { 
                                                        nooverride: '1'
                                                        } 
                                          } 
        var URL = nav.navigate(pageReference); 
     }
})
This leaves the user with a modal over a blank page (the original page context is lost)
Hitting Edit opens a new page with a modal (which is not what the documentation states should happen)

If the user cancels, they are left with a blank page
Hitting Cancel leaves the user on a blank page

If the user hits save, they page is broken
Hitting Save breaks the page

3) Complete re-development of entire flow This has issues because lightning:recordform does not replicate the detail page layout, so we would need to manually build the edit page and keep it in-line with any page layout changes which we make in the administration interface. This is an unrealistic expectation.

Are we missing the best practice way of creating overrides which can conditionally return users to the "Standard" behaviour? This was possible in Classic but seems to be unavailable in Lightning (despite the documentation implying this should be possible.
Sanjay Bhati 95Sanjay Bhati 95
Hi Big,

Here is another way that can fullfill your requirement

1. Create a lightningComponent with lightning:actionOverride interface.
a. overrideEdit.cmp
<aura:component implements="force:appHostable,flexipage:availableForRecordHome,lightning:actionOverride,force:hasRecordId,force:lightningQuickAction" access="global" >
	<aura:handler name="init" value="{!this}" action="{!c.onInit}"></aura:handler>
    <force:recordEdit aura:id="edit" recordId="{!v.recordId}"/>
    <lightning:Navigation aura:Id="navService" />
    <lightning:button label="Save" onclick="{!c.save}"/>
</aura:component>
b. overrideEdit.controller
({ 
    onInit : function(component, event, helper) {
    },
    save : function(component, event, helper) {
        component.find("edit").get("e.recordSave").fire();
        var nav = component.find("navService"); 
        console.log(component.get("v.rId"));
        var pageReference = { 
            "type": "standard__recordPage", 
            "attributes": {
                "recordId": component.get("v.recordId"),
                "actionName": "view"
            }
        } 
        var URL = nav.navigate(pageReference);
    }
})

2. Override the Edit button in lightning with overrideEdit.cmp component.
 
skkbskkb
Hi Big,

Could you please confirm if you were able to solve your problem with Sanjay's code? Or did you find any other better solution?

Thank you