Lightning RecordForm : A Powerful tool with Customization

Lightning, Lightning, Lightning… With each new day we found something interesting in Lightning. There are many new things coming in lightning that’s make us to try our hand on all of them. Previously if we need to create Edit or detail page we need to manually create them with all custom code and then we can use Lightning:recordEditForm or LightningDataService.

But that still take lots of code. But now we have lightning:recordForm, which enables usto quickly create forms to add, view, or update a record. Using this component to create record forms is easier than building forms manually with lightning:recordEditForm and lightning:recordViewForm.

Using a single line of code we can create full page layout.

<lightning:recordForm recordId="001XXXXXX" objectApiName="Account" layoutType="Full" mode="view" />

But what if we need to add some custom validation before creating record or need to check some detail or update some fields before saving the record then we can also customize this as well. Today we will take an example where we will use onsubmit to save the record and then redirect to record detail page.

Lightning Record  Form.gif

Here for demo purpose I didn’t done much customization but you can make changes. Also don’t forget to stop the standard flow else it will create two records for you.

As this component is generic so you can use it with any object to quickly get the edit page or create new record.

Did you want to add anything or have any question, please let me know in comments section. Happy programming 🙂


6 thoughts on “Lightning RecordForm : A Powerful tool with Customization

  1. Is this code working for you because in your Apex code you have taken map and while putting value in that map, for each field of data type other than String it will give error “Illegal Assignment from String to Date” (for example).

  2. Thanks for the info Tushar. I have a question on whether we can group set of fields as sections using lightning:recordForm?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.