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 🙂

Advertisements

15 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?

  3. Hi Tushar, Can we create a dependent layout using this.

    Example:
    1. If a picklist value= A
    Then only section A has to be shown
    1. If a picklist value= B
    Then only section B has to be shown

Leave a Reply

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