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
Dustin Moore 22Dustin Moore 22 

LWC Show/Hide in Lightening Community based on Account Record Type

Hello, 

I have a custom LWC built primarly for use in a lightening community. I need to find the correct attribute to show/hide this component based on a record type of the Account Object. 

Record Types:
Household: Hide
Office: Show
State Office: Show

Additionally, I need to be able to show/hide the options in  based on the record types

Record Types Show Options:
HouseHold: N/A component not shown on page
Office: Show Option 1 and 2
State Office: Show options 3 and 4

Please see the code below, and any help would be greatly appericated!

XML:
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata" fqn="DocGenSelector">
    <apiVersion>46.0</apiVersion>
    <isExposed>true</isExposed>
    <targets>
      <target>lightning__AppPage</target>
      <target>lightning__RecordPage</target>
      <target>lightning__HomePage</target>
      <target>lightningCommunity__Page</target>
    </targets>
</LightningComponentBundle>

HTML:
<template>
  <div style="position:relative;" class="wrapper">
    Select a report: 
    <select class="doc-gen-selector">
      <option value="eyJhY3Rpb25JZCI6ImEwMDM2MDAwMDBQYmgwTUFBUiIsImxpbmtGaWVsZElkIjoiSWQifQ==">VOCA Office Last Quarter</option>
      <option value="eyJhY3Rpb25JZCI6ImEwMDFSMDAwMDBkbE1KU1FBMiIsImxpbmtGaWVsZElkIjoiSWQifQ==">MVS Office YTD</option>
      <option value="eyJhY3Rpb25JZCI6ImEwMDFSMDAwMDBkbE1KU1FBMiIsImxpbmtGaWVsZElkIjoiSWQifQ==">VOCA State Last Quarter</option>
      <option value="eyJhY3Rpb25JZCI6ImEwMDFSMDAwMDBkbE1KU1FBMiIsImxpbmtGaWVsZElkIjoiSWQifQ==">MVS State YTD</option>
    </select>
    <button title="Run the selected action" type="button" class="slds-button slds-button_brand" style="margin-left: 1rem" onclick={runButtonClicked}>Run</button>
    <div class="popup">
      <button class="close-popup" onclick={closePopup}>&#215;</button>
      <div class="popup-body">
        <iframe class="iframe"></iframe>
      </div>
    </div>
  </div>
</template>


​​​​​​​

 
Ravi Dutt SharmaRavi Dutt Sharma
You should wrap this component in another component which will fetch the record type name for you. I am assuming you will place the wrapper component in the account detail page, hence the wrapper component will get the recordId automatically by having @api recordId in your javascript controller. Now since you have recordId, you can use getRecord from UI API to fetch the record type name by passing in the recordId. The record type name will be passed to your inner component and then you can conditionally hide/show the contents based on the record type name.

Refer this link for getting record id: https://developer.salesforce.com/docs/component-library/documentation/lwc/use_record_context
Refer this link for UI API: https://developer.salesforce.com/docs/component-library/documentation/lwc/use_record_context