Newer Version Available
lightning:recordViewForm
A lightning:recordViewForm component is a wrapper component that accepts a record ID and is used to display one or more fields and labels associated with that record using lightning:outputField. lightning:recordViewForm requires a record ID to display the fields on the record. It doesn't require additional Apex controllers or Lightning Data Service to display record data. This component also takes care of field-level security and sharing for you, so users see only the data they have access to.
To display the fields on a record, specify the fields using lightning:outputField.
1<aura:component>
2 <lightning:recordViewForm recordId="001XXXXXXXXXXXXXXX" objectApiName="My_Contact__c">
3 <div class="slds-box">
4 <lightning:outputField fieldName="Name" />
5 <lightning:outputField fieldName="Email__c" />
6 </div>
7 </lightning:recordViewForm>
8</aura:component>For more information, see the lightning:outputField documentation.
Working with the View Layout
To create a multi-column layout for your record view, use the Grid utility classes in Lightning Design System. This example creates a two-column layout.
1<aura:component>
2 <lightning:recordViewForm recordId="001XXXXXXXXXXXXXXX" objectApiName="My_Contact__c">
3 <div class="slds-grid">
4 <div class="slds-col slds-size_1-of-2">
5 <!-- Your lightning:outputField components here -->
6 </div>
7 <div class="slds-col slds-size_1-of-2">
8 <!-- More lightning:outputField components here -->
9 </div>
10 </div>
11</lightning:recordViewForm>
12</aura:component>Attributes
| Attribute Name | Attribute Type | Description | Required? |
|---|---|---|---|
| body | Component[] | The body of the component. In markup, this is everything in the body of the tag. | |
| recordId | String | The ID of the record to be displayed. | Yes |
| objectApiName | String | The API name of the object. | Yes |