function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Chandan NagarChandan Nagar 

Want to create a form and bind data from an object.

Hi all,
i am trying to create a lightning component which shows retrieves data from an object and displays that in a field as readonly. Since i am new to salesforce i am stuck in the beginning. I have used accordian to create section but not able to create a form and display values form an object.
Any kind of help is appreciated to jump start this.
The page should look like this with value from a custom object:
User-added image
Best Answer chosen by Chandan Nagar
Deepali KulshresthaDeepali Kulshrestha
Hi Chandan,

As your requirement ,you can acheive it using lightning-record-form:

1.Viewing a Record with Option to Edit Fields:

  Use mode="view" and pass the ID of the record and the corresponding object API name to be displayed. Specify the fields using the fields attribute, or layout-type attribute to display all the fields defined on the Full or Compact layout.

  The view mode loads the form using output fields with inline editing enabled. You can edit fields that are marked updateable in the User Interface API. If the user clicks an edit icon next to a field, all fields that are updateable become editable, and the form displays Cancel and Save buttons.

  This example creates a form for an account record in view mode with fields from the full layout. Update the record ID with your own.
<aura:component>
  <lightning-record-form
    record-id="001XXXXXXXXXXXXXXX"   <!-- record id that you want to show -->
    object-api-name="Account"  <!-- object Name-->
    layout-type="Full"
    mode="view">    <!-- mode in which u want to give access -->
  </lightning-record-form>
  </aura:component>

2.Viewing a Record with Read-Only Fields:

  Use mode="readonly" and pass the ID of the record and the corresponding object API name to be displayed. Specify the fields using the fields attribute, or layout-type attribute to display all the fields defined on the Full or Compact layout.

  The readonly mode loads the form with output fields only, and without Cancel or Save buttons.
 
  This example creates a form for an account record in readonly mode with a single column and fields from the compact layout. Update the record ID with your own.
<aura:component>
  <lightning-record-form
    record-id="001XXXXXXXXXXXXXXX" <!-- record id that you want to show -->
    object-api-name="Account"  <!-- object Name-->
    layout-type="Compact"  
    columns="1"
    mode="readonly">   <!-- mode in which u want to give access -->
  </lightning-record-form>
   </aura:component>

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com