Salesforce Interview Questions & Answers Book is now available!

Grab Now

LWC

Using lightning-record-view-from in LWC

When you want to fetch a record in LWC without using JavaScript and Apex code then we will be using lightning-record-view-form.

By Teja, ex-Salesforce engineer · Updated April 4, 2021 · 1 min read

This blog post is the next post in the series of posts that are targeted towards understanding the tags in LDS.

When you want to fetch a record in LWC without using JavaScript and Apex code then we will be using lightning-record-view-form.

This tag has to be provided object-api-name and record-id attributes to fetch the record and display it back to the users.

Here is the snippet of the code.

<template>
	<lightning-record-view-form 
    object-api-name="Account" 
    record-id={recordId}>
    <lightning-output-field field-nam="Name"></lightning-output-field>    
    <lightning-output-field field-nam="Industry"></lightning-output-field>    
	<lightning-output-field field-nam="Rating"></lightning-output-field>    
    </lightning-record-view-form>
</template>

Using lightning-record-edit-from in LWC

import { LightningElement, api } from 'lwc';

export default class HelloWorld extends LightningElement {
    @api
    recordId;
}

helloWorld.js in LWC

Hope this is helpful!

Learn it by building it

Every course, every code repository, the discussion group and certificates of completion — one subscription.

Keep me in the loop!

Email me when a new episode is published (promise, I will not spam you)

You're signing up to receive emails from Salesforce Casts