SalesforceBlue

Feel the rhythm of Salesforce

Aura

Lightning Record View Form Simplified

In the previous part, we learn about the Lightning Record Form and its usage to create a form to view records in read-only mode. However, if you may require extra flexibility in creating your form in terms of customizing the form layout or custom rendering of record data then you can use a Lightning Record View Form instead.

Use the lightning:recordViewForm component to create a form that displays Salesforce record data for specified fields associated with that record. The fields are rendered with their labels and current values as read-only.

To specify read-only fields, use lightning:outputField components inside lightning:recordViewForm.

lightning:recordViewForm requires a record ID to display the fields on the record.

This component also takes care of field-level security and sharing for you, so users see only the data they have access to.

lightning:recordViewForm Example:

Please create an Aura Component with the name MyLightningRecordViewForm and save the following code for this example:

<aura:component>
    <aura:attribute name="recordId" type="String" default="0012x00000OqGYjAAN" />
    <aura:attribute name="objectApiName" type="String" default="Account" />

    <lightning:recordViewForm recordId="{!v.recordId}" objectApiName="{!v.objectApiName}">
        <div class="slds-box">
            <lightning:outputField fieldName="Name" />
            <lightning:outputField fieldName="Industry" />
            <lightning:outputField fieldName="AnnualRevenue" />
        </div>
    </lightning:recordViewForm>

</aura:component>	

In this example, we have customized the form layout by using only three fields inside a div. You can modify this code and have custom form layout as per your requirement.

Below is the preview of this component:

Lightning Record View Form

You can check all the attributes available for lightning:recordViewForm over here:
https://developer.salesforce.com/docs/component-library/bundle/lightning:recordViewForm/specification

Thank you for visiting SalesforceBlue.com
If you have any queries feel free to write down a comment below 🙂


Leave a Reply

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