top of page
Writer's pictureSaurabh Singh

Dynamic Lightning-Record-Edit-Form

Updated: Mar 7, 2023

In this blog post, I will show you how to use a FieldSet to dynamically display fields in a lightning-record-edit-form component in Lightning Web Component (LWC).


A FieldSet is a collection of fields that you want to display on a record page. You can create a FieldSet on any object and choose those fields you want to display dynamically.


1. Create a FieldSet on any object. For this example, I will create a FieldSet on the Account object and name it `DynamicFields`. I will add the following fields to the FieldSet: Name, Industry, Type, Phone and Website.


2. Create an LWC component and name it `dynamicRecordEditForm`. In the HTML file of the component, add the following code:

3. In the JS file of the component, add the following code:

4. Create an Apex class and name it DynamicRecordEditFormController. In the Apex class, add the following code:

5. Add your LWC component to any record page that uses the Account object. For this example, I will add it to the Account Record Page using Lightning App Builder.


Note: If you don't want to use fielset, you can also use custom metadata to store field API. Only the apex class code will changed.

Subscribe to SFDC BLOGS

©2019 by SFDC Blogs.

bottom of page