Create Confirm Notifications In Lightning web components

  In summer 22, Salesforce released a new module LightningConfirm to create alert notifications in LWC components.

LWC Confirm Notification

SampleConfirmNotification.html

<template>
    <lightning-button onclick={handleConfirm} label="Open Confirm Modal">
    </lightning-button>
</template>

SampleConfirmNotification.js

import { LightningElement } from 'lwc';
import LightningConfirm from 'lightning/confirm';

export default class SampleConfirmNotification extends LightningElement {
    async handleConfirm() {
        const result = await LightningConfirm.open({
            message: 'This is a sample Confirm message',
            variant: 'headerless',
            label: 'this is the sample label value',
        });
    }
}

SampleConfirmNotification.js-meta.xml

<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>55.0</apiVersion>
    <isExposed>false</isExposed>
</LightningComponentBundle>

Sample Confirm window:

confirm-notification

Also found above code in Tech Shorts Git repo

Labels:
LWC
Join the conversation