ID of record created with force:recordData, the Lightning Data Service

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

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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.

Method 2

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");

Method 3

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;

Method 4

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


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x