So today we will check Lightning Base component, Lightning:RecordEditForm. In the last post we check how we can use the Lightning:recordForm. Which is a great tool provides many features. But there are some limitation. For Example, we can’t prepopulate data in that.
So using Lightning:RecordEditForm we can createa new record or edit an existing record, check our custom validation and store the data into Salesforce without using single line of apex code.
Lightning:inputfield check the basic validation of data format and required field. So we don’t need to worry about them. In case we get any system validation error it will show them using lightning:messages tag. It will also support dependent picklist out of the box. So most of the functions are supported OOTB.
Below we have sample code in which we have prepopulated LastName.
So we have different events here onload, onsubmit, onsuccess. While using onload we can prepopulate some of the fields. And onsubmit we can perform our own custom validations. Here we need to stop standard flow if we want to use our custom code else it will create multiple records.
After the record was save successfully, we are using
lightning:navigation component to redirect to detail page. It is a new component launched recently. We use this to navigate to a given pageReference or to generate a URL from a pageReference. So here we are using this component to go to the record detail page
So now we have Lightning Data Service which we can use to create basic Edit/Detail screens in Lightning. Lightning Data Service reduces the need of Apex so we can easily push our code in production instance with less maintance.
We also have lightning-record-edit-form which is an upgrade version in Lightning Web Components.
Do you want to add anything here or if you have any questions, let me know in comments section. Happy programming 🙂