lightning:recordForm is one of the most useful components provided in the Summer 18 release, lightning:recordForm does all the heavy lifting for you. You can edit, view and create a record using the same lightning:recordForm component without even worrying about checking the access level of the user accessing the lightning:recordForm component, isn't that great. Using this component to create record forms is easier than building forms manually with lightning:recordEditForm and lightning:recordViewForm.

The lightning:recordForm has the following attributes -

  • objectApiName - The API name of the object.
  • recordId - The Id of the record to be displayed/edited, if no recordId is passed then the form creates a new record.
  • fields - The list of API names of the fields that will be displayed on the form.
  • columns - Specifies the number of columns for the form.
  • layoutType - Possible values Full and Compact.
  • mode - Specifies the interaction and display style for the form. The 3 possible modes are
    • edit - The form is opened in edit mode and can be used to update and create new records. If the record Id is passed then the record is updated otherwise a new record is created.
    • readonly - Users can only see the record and no edit functionality is provided.
    • view - If no mode is provided then by default view mode is selected. The record is loaded on the display form but also give the edit option to the users by providing them with the edit button.

Let's see lightning:recordForm in action.



The result is a lightning form which is capable of displaying and editing the record without any additional coding

Here are a few points that should be remembered while using the component

  • The Event and Task objects are not supported. Want to know more about supported objects see the User Interface API Developer Guide.
  • If you want to create a new record, recordId attribute should be blank.
  • Both the attribute layoutType or fields can be used in the same lighthing:recordForm component. In such a case the specified fields are loaded after the layout fields.
  • objectApiName is the only required attribute which will hold the API name of the object.
  • To override the standard save functionality override the onsubmit action
Posted in: New

Leave a Reply

Your email address will not be published. Required fields are marked *