0

I have overwritten my standard edit button for object and what I'm trying to achieve is, based on the result from an apex controller function redirect to standard edit form (with force:editRecord) or display a custom one based on some permissions. The issue I'm currently having is that, when the component launches the force:editRecord event it stays on a loop and never reaches the form.

This is my code so far:

COMPONENT:

<aura:component 
implements="force:hasRecordId,force:hasSObjectName,lightning:actionOverride" controller="BI_LEX_ModifyOrderItemControl">
<aura:attribute name="redirect" type="Boolean" default="false"/>

<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>

<p style="color:white">TEST</p>

CONTROLLER

({
doInit : function(component, event, helper) {
    var params;
    var result;
    var action = component.get("c.checkIfStandardOrCustomEdit");
    action.setCallback(this, function(response){
        if(response.getState() === 'SUCCESS'){
            result = response.getReturnValue();
            console.log(result);
            //Standard
            if(result === true){
                helper.redirectEditRecord(component);
            }
            //Custom
            else{
                //Add functionality
            }
        } 
        else{
            params = {"title":"Error","duration":10000,"type":"error","message":response.getError()[0].message};
            helper.generateToast(params);
            window.story.back();
        }
    });
    $A.enqueueAction(action);
}
})

HELPER

({
generateToast: function(params){
    var toastEvent = $A.get("e.force:showToast");
    toastEvent.setParams(params);
    toastEvent.fire();
},

redirectEditRecord : function(component){
    var editRecordEvent = $A.get("e.force:editRecord");
    editRecordEvent.setParams({
        "recordId": component.get("v.recordId")
    });
    editRecordEvent.fire();
},
})

And this is what happens actually:

enter image description here

Is this an error bug or am I doing something wrong? Cause it seems that it's always calling the on init handler

0

What you are doing wrong is on click of the edit button, naturally, an edit event gets fired, it calls your method and based on the response you make again an edit event to get fired by using force:editRecord. So again it calls your method and again it fires your edit event. This process Continues and hence it lets you through the continuous loop.

Instead of force:editRecord if you use force:createRecord in your helper method, This will not happen.

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.