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:
Is this an error bug or am I doing something wrong? Cause it seems that it's always calling the on init handler