If you have been enjoying the development of lightning components since each release is coming up with exciting features. I liked the Lightning:RecordEditFrom and have used it in various projects. While working on a piece of a project, I liked the idea of showing fields based on the page-layout so a System Administrator can control the fields in the custom component instead of creating a change request to developers.
I used Apex Metadata API to get the fields from the layout and was showing them dynamically on the component. You can make it more configurable by adding the custom metadata types to control the page-layout assignments for the record types too. Here I am going to explain a simple use case.
ABC Corp. is a retail company and they are looking for a way to update the primary contact details just by clicking a button on the account record page. For that requirement, we are going to use a custom component which is using the lightning:recordEditForm. Here we don’t want to hard-code the fields and want to allow a Salesforce Admin to add/remove fields from the view so we are going to leverage the standard page layouts here.
Following component will fulfill the ABC Corps need and they can easily update the primary contact details through this custom component. Page layout details will be parsed in the apex controller by using the Apex Metadata API and recordEditForm will render fields dynamically. Although it isn’t a foolproof solution, you can refer it in your development. Here is the working example.
If you have any suggestion/comments then please feel free to reach out to me.