You might be loving Lightning Data Service and its capabilities. It Creates an editable form or display form for a record. This component requires API version 43.0 and later. What if you are capable of doing the same thing without writing a single line of code. Yes, You can do that. How?
Lightning Experience Comes with Standard Component called Related Record Component which you can use to give your users the record details they need most. Use the Related Record component to customize your Lightning pages and display the details of a related record, including the parent record, on any record page. This feature is new in Lightning Experience.
Want to show details about an associated contact on a case? Want to show the details of a case’s parent case? To top it off, your users will love the built-in record creation, inline edit, and ability to unlink a record and link a new one.
Under the covers, the component uses quick actions and global actions to create and update the records. If there are no actions available for your lookup, follow the links in the Lightning App Builder property editor to create the actions. You can select any associated lookup field to display related details—even lookups for custom objects.
Steps to Follow
Here, We are creating Action of type Update a record. You can create an action of type Create a record also as per requirement.
- In Setup, in the Quick Find box, enter the name of the object that you want to add actions to. For this example, enter Opportunities, then select Buttons, Links, and Actions.
- Click New Action to see which types of actions are available.
- From the Action Type dropdown list, select the action to add. In this case, select Update a Record.
- Enter a label and description for the action.
- Click Save.The next page shows the default fields that you can update. For the example, add the Probability (%) and Typefields.
- Drag Probability (%) and Type below the Stage field in the workspace. To select multiple fields, hold down Ctrl (for Windows) or Cmd (for macOS).
- Click Save.You added the Update Opportunity action to the Opportunities object.
Now, You have created the action. Its time to add the action to your Lightning page Layout using Lightning App Builder.
Adding the action to Lightning Page Layout
- In Salesforce, click the Opportunity tab. Click any record name. (If no records appear in the Recently Viewed list, change to the All Accounts list.)
- Click the gear icon(setup), then select Edit Page to open the Lightning App Builder.
- Drag the Related Record standard component from the Lightning Components list to the page and place it where ever you want on the canvas.
- Click Save.
- Click Activate.
- Click Assign as Org Default, then click Save.
- Click Back to return to the record home page.
Now, we have added the action to Lightning page Layout. Its time to see how it works.
Any change in this component will be automatically reflected in record. That’s really great. Admins got more power now. Without writing a single line of code, You can create reusable Form to display a set of fields or create a record form and put it on Lightning Page.
Note:- All the validation rule, sharing setting and other standard features will be respected by this Component.