I am using the lightning:recordForm for creating the record

 <lightning:recordForm aura:id="recordViewForm"
                              layoutType ="Full"

onSuccess : function(component, event, helper) {

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



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. Mar 1 '19 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 '19 at 1:11
  • I get the same error as "undefined" :( Mar 1 '19 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 '19 at 3:15
  • Perfect! Thanks Jayant Mar 1 '19 at 17:07

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