I'm trying to override the standard 'Create' button of Salesforce using a generic lightning component. I have a custom slds modal with some lightning components. As its not possible to open up the create record modal with these additional components included, Im doing a database insert with some dummy values and then loading the record in edit mode using force:recordEdit with the created record's id.
force:recordData is used to load the record with the created Id. This is to delete the created dummy record in case the user clicks cancel/exit the modal.
However, Im getting the below error while clicking the 'Cancel' button.
While inspected with lightning inspector, its found that the attributes "targetfields" and "targetrecord" are coming in as null.
Strange thing is that this happens only for lead object. For overrding Account and Contacts, force:recordData loads up correctly with proper targetfields and targetRecord.
Console logs for Account Object
Console logs for Lead Object
Below is the how I included force:recordData
<force:recordData aura:id="recordHandler"
recordId="{!v.recordId}"
fields="Id"
targetError="{!v.recordError}"
/>
Client Side Controller
hideModal : function(component, event, helper) {
var recordId = component.get("v.recordId");
var sobjectName = component.get("v.sobjectName");
component.find("recordHandler").deleteRecord($A.getCallback(function(deleteResult) {
// NOTE: If you want a specific behavior(an action or UI behavior) when this action is successful
// then handle that in a callback (generic logic when record is changed should be handled in recordUpdated event handler)
if (deleteResult.state === "SUCCESS" || deleteResult.state === "DRAFT") {
// record is deleted
console.log("Record is deleted.");
helper.navigateToHome(component, sobjectName);
} else if (deleteResult.state === "INCOMPLETE") {
console.log("User is offline, device doesn't support drafts.");
} else if (deleteResult.state === "ERROR") {
console.log('Problem deleting record, error: ' + JSON.stringify(deleteResult.error));
} else {
console.log('Unknown problem, state: ' + deleteResult.state + ', error: ' + JSON.stringify(deleteResult.error));
}
}));
},