You need to sign in to do that
Don't have an account?
monalisa das 46
How to get record Id from Lightning record edit form, when used for record insert?
I have a requirement where I am making use of lightning:recordEditForm to create a new record. I am using standard save functionality. After successful save of record I need to make use of the record Id. Is there is any native way to get Id of record without making server call?
I thought that after successful record creation the recordId attribute will get populated with appropriate value and will give proper value via this
But this returns undefined.
Though I can make a server call with appropriate filters in SOQL to get Id of the record, but seems there should be some easier way around without server call.
<lightning:recordEditForm onsuccess="{!c.handleSuccess}" onerror="{!c.handleError}" aura:id="recordEditForm" objectApiName="Address__c"> <lightning:messages /> <lightning:inputField fieldName="Customer__c" value="{!v.accountRecord.Id}" class='slds-hide'/> <aura:iteration items="{!v.displayListAddress}" var="item" > <lightning:inputField fieldName="{!item}" onchange="{!c.fieldValChange}"/> </aura:iteration> <div class="slds-modal__footer"> <div class="slds-align_absolute-center"> <lightning:button label="Cancel" title="Neutral action" onclick="{! c.closeEdit }"/> <lightning:button variant="brand" type="submit" name="save" label="Save" /> </div> </div>
I thought that after successful record creation the recordId attribute will get populated with appropriate value and will give proper value via this
alert("Id : "+component.find("recordEditForm").get("v.recordId"));
But this returns undefined.
Though I can make a server call with appropriate filters in SOQL to get Id of the record, but seems there should be some easier way around without server call.
To get the record id, add below code to your JS controller.
Please mark this as the best answer if it resolves your issue. Thanks.