I am using lightning:recordEditForm and lightning:inputField for creating a new record. this component is being used inside a lightning community builder. When i click the submit button, i am able to create a new record in my custom object. However i need the created record ID as i need to pass it in the URL for the next page.
-
Wouldn't that be your v.recordid itself that get auto-populated ?– brovasiFeb 6, 2018 at 11:47
-
I am using this inside of a community. so i believe the recordid will be NULL.– Ravi NarayananFeb 6, 2018 at 11:58
-
Is that even supported by community ? I know LDS is not quite supported yet.– brovasiFeb 6, 2018 at 12:02
-
"Lightning Data Service is only available in Lightning Experience and the Salesforce app. Using Lightning Data Service in other containers, such as Lightning Components for Visualforce, Lightning Out, or Communities isn’t supported. This is true even if these containers are accessed inside Lightning Experience or the Salesforce mobile app, for example, a Visualforce page added to Lightning Experience." from developer.salesforce.com/docs/atlas.en-us.lightning.meta/…– brovasiFeb 6, 2018 at 12:04
-
But i am able to create a record. Just that i want to get the created record ID.– Ravi NarayananFeb 6, 2018 at 14:11
1 Answer
The below code will give us the created record id.
handleSuccess : function(component, event, helper) {
var payload = event.getParams().response;
console.log(payload.id);
}
-
2
-
I want to add two things: 1. For those who are Apex devs with limited Javascript experience, case is important in this context.
console.log(payload.id)
will return the record ID;console.log(payload.Id)
will returnundefined
. 2. The documentation linked by iloveseven contains the correct way to retrieve the ID, but it also contains an error:handleSuccess: function(component, event) { var updatedRecord = JSON.parse(JSON.stringify(event.getParams())); console.log('onsuccess: ', updatedRecord.id); }
returnsundefined
. Mar 4, 2019 at 21:19 -
Also, ensure you use lower case "id", and not "Id" as javascript is case sensitive. Mar 6, 2019 at 21:14
-
Just want to know how can i use this in LWC,my requirement is in lwc and it throwing error . Apr 16, 2020 at 7:34