1

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.

enter image description here

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

enter image description here

Console logs for Lead Object

enter image description here 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));
    }
}));
},
  • I have also tried creating the component dynamically after getting the created record's id and then calling deleteRecord method. However, its resulting same error. – Vishnu J Menon Sep 26 '17 at 17:03
  • Can you provide business requirement? What are you doing is called as dirty programming ? which should be discouraged :) – Pranay Jaiswal Sep 26 '17 at 17:03
  • The business requirement is that we have an API which can be called to get address suggestions. User can set in mappings by himself to map the individual address components of the api response (eg : street, city, zip code etc) to fields of a Salesforce objects. We are trying to use this API to provide autocomplete suggestions for address fields of Salesforce records while creating/editing. User can select the autocomplete suggestion, the mapping he set for the object from a drop down list and on clicking a button, the record must be reloaded back with selected suggestion in the address fields – Vishnu J Menon Sep 26 '17 at 17:21
0

I've noticed, you are working with Lead SObject. I ran into an issue with force:recordData not displaying data of a Lead record in one of my components and after some investigation found out that it is not currently supported by Lightning Data Service as this document states: https://developer.salesforce.com/docs/atlas.en-us.208.0.lightning.meta/lightning/data_service_considerations.htm

Also this presentation comment states: 'Custom objects supported completely • Opportunity and Lead currently not supported • Formatted field values not supported completely'

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.