1

I have a requirement where LWC component is fired everytime when a case is opened,I want to change LWC component to work only for NEW cases,what changes needs to be done in the LWC to make it work only for specific case types which are in NEW status

Here is JS code

    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);
       }

    }

here is HTML

    <template>

    </template>

here is 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>
6
  • What does "fired" mean? Where is this LWC exposed in the user interface? Commented Nov 17, 2021 at 18:41
  • with fired meant LWC component is displayed on CASE page record ,so each time user opens case this LWC on case page record is displayed even on existing case records,need a way to make this component get displayed only on NEW case records Commented Nov 17, 2021 at 19:04
  • especially need this for say RecordType.Name = 'XXX' Commented Nov 17, 2021 at 19:29
  • Once the record is saved, it's not new. Are you overriding the Record Create action? Commented Nov 17, 2021 at 20:05
  • No its a very basic LWC which displays justa a Toastmessage on Cases ,havent overridden any action up until now Commented Nov 17, 2021 at 20:40

1 Answer 1

1

Few ways to do it.

  1. Ignore LWC completely. Does it have to be a "toast" at all? You could drop to the page a Rich Text Area field, put some text in red and use conditional display rules. Job done, zero code.

enter image description here

  1. Similar - still use your component as is, but use the component visibility rules to make it display (run) only on New Cases.

  2. Edit your component to be something like this

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'
            }));
        }
    }
}

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.