es.davy.ai

Preguntas y respuestas de programación confiables

¿Tienes una pregunta?

Si tienes alguna pregunta, puedes hacerla a continuación o ingresar lo que estás buscando.

Cómo hacer que Salesforce LWC solo funcione para casos nuevos y no en casos existentes.

Tengo un requerimiento en el cual el componente LWC se dispara cada vez que se abre un caso. Quiero cambiar el componente LWC para que solo funcione para los casos NUEVOS, ¿qué cambios se necesitan hacer en el LWC para que funcione solo para tipos de caso específicos que estén en estado NUEVO?

Aquí está el código en JS

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

export default class CaseTypeInformation extends LightningElement {

connectedCallback() {
var toast = new ShowToastEvent({
'title': 'Campos de nivel 1, nivel 2 y nivel 3 del tipo de caso ',
'message': 'deben seleccionarse antes de guardar'
});
this.dispatchEvent(toast);
}

}

Aquí está el HTML

<pre><code><template>
</code></pre>

</template>

Aquí está el metaxml

<pre><code> <?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>lightningRecordPage</target>
<target>lightningAppPage</target>
<target>lightning__HomePage</target>
</targets>
</lightningcomponentbundle>
</code></pre>

“`

Tags:  , , ,

Answer

  1. Avatar for davy.ai

    Para que el componente LWC funcione solo con casos NUEVOS, debe agregar una condición en el método connectedCallback() del código JavaScript. Puede utilizar el campo Case.Status para verificar si el caso está en estado NUEVO.

    import { LightningElement } from 'lwc';
    import { ShowToastEvent } from 'lightning/platformShowToastEvent';
    import { getRecord } from 'lightning/uiRecordApi';
    import CASE_OBJECT from '@salesforce/schema/Case';
    import STATUS_FIELD from '@salesforce/schema/Case.Status';
    
    export default class CaseTypeInformation extends LightningElement {
    
        connectedCallback() {
            getRecord({ recordId: this.recordId, fields: [STATUS_FIELD] })
                .then(record => {
                    if (record.fields.Status.value === 'NEW') {
                        var toast = new ShowToastEvent({
                            'title': 'Campos de Nivel 1, Nivel 2 y Nivel 3 del tipo de caso',
                            'message': 'deben ser seleccionados antes de guardar'
                        });
                        this.dispatchEvent(toast);
                    }
                });
        }
    }
    

Comments are closed.