0

This question already has an answer here:

I am using the lightning:recordForm for creating the record

 <lightning:recordForm aura:id="recordViewForm"
                              objectApiName="{!v.sObjectName}"
                              columns="2"
                              recordId="{!v.recordId}"
                              layoutType ="Full"
                              mode="edit"
                              onsuccess="{!c.onSuccess}"
                              onsubmit="{!c.onSubmit}"
                              onload="{!c.onLoad}"
                              onerror="{!c.onError}"/> 


onSuccess : function(component, event, helper) {

   console.log('event response==='+ (event.getParams("response")).Id);
   // this log statement returns --> event response===undefined

}

marked as duplicate by glls, Mark Pond, David Reed, Reshma, Derek F Mar 1 at 13:54

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

4

UPDATE

Seems the approach to retrieve the response is incorrectly mentioned in the documentation. Updated the usage based on a quick test.


This is from the documentation for lightning:recordForm:

For information about Event Return Parameters and examples of event handlers, see the documentation for lightning:recordEditForm.

And based on the documentation for lightning:recordEditForm, the response is returned as JSON, so to get the Id of the record, you will need to change your function as below:

onSuccess : function(component, event, helper) {
    // as mentioned in the documentation as of today, the one below does not work
    // var responseJSON = event.getParams().response;

    // based on a quick test, this works
    var responseJSON = event.getParams();
    var recordId = responseJSON.id;    
}

On a side not, I see you have specified recordId="{!v.recordId}", which is not required to be passed if you are using this for a create scenario.

  • In this case, there would not be any recordId hence this will be used as create form. In edit scenario a recordId would exist and it would load the edit form for the user to create. That’s why I have used recordId in this component. – SFDC_BigDog Mar 1 at 1:03
  • 1
    I just wanted to highlight as it seemed unusual for a create scenario but as long as you have handled it, works fine. – Jayant Das Mar 1 at 1:11
  • I get the same error as "undefined" :( – SFDC_BigDog Mar 1 at 1:52
  • @SFDC_BigDog I updated my answer based on a quick test. That should work. Seems it's incorrectly mentioned in the docs. – Jayant Das Mar 1 at 3:15
  • Perfect! Thanks Jayant – SFDC_BigDog Mar 1 at 17:07

Not the answer you're looking for? Browse other questions tagged or ask your own question.