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

Get record Type in LWC

Hi ,

Based on record type need to render lwc.html . how to achieve this scenario.

AshwiniAshwini (Salesforce Developers) 
Hi @KMK91,
Can you elaborate more on the ask?
Hi Aswini,
I have different recordtypes, i'm displaying  like 
A, B, C sections in page when click on button and i dont' want to display B section based on record type .

Arun Kumar 1141Arun Kumar 1141


To achieve this you can create a variable in js and use the apex controller to get the record type and then based on the value you can set the condition in HTML of your LWC component.

    <template if:true={RecordType=='A'}>
        <p>This is content for Record Type A.</p>
    <template if:true={RecordType=='B'}>
        <p>This is content for Record Type B.</p>
    <template if:true={RecordType=='C'}>
        <p>This is default content for other Record Types.</p>
import { LightningElement, api, wire } from 'lwc';
import getRecordType from '@salesforce/apex/RecordTypeController.getRecordType';

export default class Example extends LightningElement {
    @api recordId; // Assuming you have a property to store the record Id

    @wire(getRecordType, { recordId: '$recordId' })
    wiredRecordType({ error, data }) {
        if (data) {
            this.recordType = data;
            // Now, this.recordType contains the record type name
        } else if (error) {
            // Handle any errors

I hope this will help you.