如何使 Salesforce LWC 仅适用于新案例而不适用于现有案例

How To Make Salesforce LWC work only for New Cases and Not on Existing cases

我有一个要求,每次打开案例时都会触发 LWC 组件,我想将 LWC 组件更改为仅适用于新案例,需要在 LWC 中进行哪些更改才能使其仅适用于特定的处于 NEW status

的案例类型

这是JS代码

    import { LightningElement } from 'lwc';
    import {ShowToastEvent} from 'lightning/platformShowToastEvent';

     export default class CaseTypeInformation extends LightningElement {


    connectedCallback() {
        var toast = new ShowToastEvent({
                 'title': 'Case Type Level 1, level 2 and level 3 fields ',
                 'message': 'must be selected before saving'
             });
             this.dispatchEvent(toast);
       }

    }

这里是HTML

    <template>

    </template>

这里是 metaxml

     <?xml version="1.0" encoding="UTF-8"?>
     <LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>52.0</apiVersion>
    <isExposed>true</isExposed>
    <masterLabel> CaseType Levels Info Component</masterLabel>
    <description> CaseType Levels Info Component.</description>
    <targets>
      <target>lightning__RecordPage</target>
      <target>lightning__AppPage</target>
      <target>lightning__HomePage</target>
     </targets>
    </LightningComponentBundle>

几种方法。

  1. 完全忽略LWC。它必须是“吐司”吗?您可以将 Rich Text Area 字段拖放到页面上,将一些文本设为红色并使用条件显示规则。工作完成,零代码。

  1. 类似 - 仍按原样使用您的组件,但使用组件可见性规则使其仅在新案例中显示 (运行)。

  2. 将您的组件编辑成这样

import { LightningElement, api, wire } from 'lwc';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { getRecord } from 'lightning/uiRecordApi';
import CASE_STATUS_FIELD from '@salesforce/schema/Case.Status';

export default class CaseTypeInformation extends LightningElement {
    @api recordId;

    @wire(getRecord, { recordId: '$recordId', fields: [CASE_STATUS_FIELD] }) wiredCase({ error, data }){
        if(data && data.fields.Status.value === 'New'){
            this.dispatchEvent(new ShowToastEvent({
                'title': 'Case Type Level 1, level 2 and level 3 fields ',
                'message': 'must be selected before saving'
            }));
        }
    }
}