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
KMK91KMK91 

Get record Type in LWC

Hi ,

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

Thanks
KMK
AshwiniAshwini (Salesforce Developers) 
Hi @KMK91,
Can you elaborate more on the ask?
KMK91KMK91
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 .

Thanks
KMK
Arun Kumar 1141Arun Kumar 1141

Hi,

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>
    <template if:true={RecordType=='A'}>
        <p>This is content for Record Type A.</p>
    </template>
    <template if:true={RecordType=='B'}>
        <p>This is content for Record Type B.</p>
    </template>
    <template if:true={RecordType=='C'}>
        <p>This is default content for other Record Types.</p>
    </template>
</template>
 
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
    recordType;

    @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.

Thanks!
​​​​​​​