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 ? – Cloud Ninja Feb 6 '18 at 11:47
  • I am using this inside of a community. so i believe the recordid will be NULL. – Ravi Narayanan Feb 6 '18 at 11:58
  • Is that even supported by community ? I know LDS is not quite supported yet. – Cloud Ninja Feb 6 '18 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/… – Cloud Ninja Feb 6 '18 at 12:04
  • But i am able to create a record. Just that i want to get the created record ID. – Ravi Narayanan Feb 6 '18 at 14:11

The below code will give us the created record id.

handleSuccess : function(component, event, helper) {
var payload = event.getParams().response;
  • 2
    For those who need more info on it here is a documentation. – iloveseven Aug 17 '18 at 16:32
  • 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 return undefined. 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); } returns undefined. – womanwhodevs Mar 4 '19 at 21:19
  • Also, ensure you use lower case "id", and not "Id" as javascript is case sensitive. – Nicholas Zozaya Mar 6 '19 at 21:14
  • Just want to know how can i use this in LWC,my requirement is in lwc and it throwing error . – Sahil Malhotra Apr 16 '20 at 7:34

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.