How can I get the ID of a record being inserted with force:recordData?


The recordId property will be populated with the ID of the new record once it's created.

The solution is not hard to find, it's here.

| improve this answer | |

Bind a record Id to the object, and you should be able to get it back out:

<aura:attribute name="recordId" type="Id" />
<force:recordData recordId="{!v.recordId}" ...
<aura:handler name="change" value="{!v.recordId}" action="{!c.recordSaved}" />

Or, you can get the value after force:recordSaveSuccess from the recordId attribute:

<force:recordData aura:id="recordData" ...

var recordData = component.find("recordData").get("v.recordId");
| improve this answer | |

When you call the saveRecord method on the recordData component from javascript...

createNewExam : function(component, event, helper){
    component.find("ClonedExamCreator").saveRecord(function(saveResult) {

it is given an object of type RecordSaveResult as a callback. From this object get simply use recordID attribute.

let newExamID = saveResult.recordId;
| improve this answer | |

saveResult.recordId is correct; state -> SUCCESS recordId -> a23O00000012YREIA2 error -> undefined entityApiName -> OrderInfo__c entityLabel -> OrderInfo action -> SecureObject: [object Object]{ key: {"namespace":"c"} }

| improve this answer | |

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.