I've built a lightning component that runs when the user clicks the standard 'New' button on the Opportunities related list on Account. My component invokes e.force.createRecord meaning it shows the Opportunity record creation modal when ran.
The Opportunity record creation modal has 3 buttons (Cancel, Save and New, and Save). Is there a way to define separate redirects for Cancel and Save? Currently I can define one redirect that gets applied to both the Cancel and Save button, via the following code:
var createRecordEvent = $A.get("e.force:createRecord");
createRecordEvent.setParams({
"entityApiName": "Opportunity",
// Prepopulate values:
"defaultFieldValues": {
"AccountId" : recordId //,
// Add more default values here if desired:
},
"panelOnDestroyCallback": function(event) {
window.location.href = "https://www.google.com";
},
"recordTypeId":rtDet.id
});
createRecordEvent.fire();
Best Answer
I would suggest using the lightning:recordEditForm
and then leverage the events provided by the component such as :
To do your custom action and for your cancel button, you can define your own method.