3

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 for returning the standard edit behaviour 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)
  2. 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) {
        console.log('HELLO DID THIS GET CALLED?');

        /*CAUSES INFINITE LOOP IN OVERRIDE CONTEXT*/
        var editRecordEvent = $A.get("e.force:editRecord");
        editRecordEvent.setParams({
            "recordId": component.get("v.recordId")
        });

        editRecordEvent.fire();

    }

})
  1. 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)

Hitting Save on the Edit Override

Component

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

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);
    }
})
  1. 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.

2

Try this: It worked in mobile Edit functionality:

({
onInit : function(component, event, helper) {

        console.log('HELLO DID THIS GET CALLED?');
        /*CAUSES INFINITE LOOP IN OVERRIDE CONTEXT **unless u specify nooverride=1***/
        var editRecordEvent = $A.get("e.force:editRecord");
        editRecordEvent.setParams({
            "recordId": component.get("v.recordId"),
            "nooverride":"1"
        });
        editRecordEvent.fire();

    }

})
  • Can't rescind my upvote, but this does not work. I get in an infinite loop. – SFDC Neuf Apr 10 at 18:47
  • Worked for me, but it's nooverride:"1", not "nooverride":"1" – SallyRothroat Apr 26 at 20:17
1

It seems that there is a way around this - It feels a bit imperfect, but it seems to work for us. You can use and fire a view event (with nooverride) immediately followed by an Edit event.

Component:

<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId,lightning:actionOverride" access="global" controller="Service_Utils">
     <aura:handler name="init" value="{!this}" action="{!c.onInit}"/>
     <lightning:navigation aura:id="navService"/>

Controller:

onInit : function(cmp, event, helper) {
    var recordId = cmp.get("v.recordId");

    var pageReference = {    
                            "type": "standard__recordPage",
                            "attributes": {
                                "recordId": recordId,
                                "actionName": "view"
                            },
                            "state":{
                                "nooverride":"1"
                            }
                        };

    var navService = cmp.find("navService");

    navService.navigate(pageReference);

    pageReference.attributes.actionName = "edit";

    navService.navigate(pageReference);

}

The user is still navigated to a new page (as is the behaviour for lighting component overrides), but they can still edit the record as per needed.

This could also work as a way to "override" overrides which have been set up in Salesforce Classic but aren't necessary in Lightning.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.