How to show toast notification in Lightning Web Component example.

Let’s talk about toast notification pop ups in Salesforce Lightning. Toast notification can pop up and display error, warning, success or information messages. The style of the notification depends on the variant of the toast. You don’t have to set variant of the toast – default value is info. To use toast in Lightning Web Component you need to import ShowToastEvent from the lightning/platformShowToastEvent module.

import { ShowToastEvent } from 'lightning/platformShowToastEvent'

Javascript Controller:

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

export default class ShowToastDemo extends LightningElement {
    showInfoToast() {
        this.showToast( 'Info Title', 'Info Message', 'info' );
    }
    showSuccessToast() {
        this.showToast( 'Success Title', 'Success Message', 'success' );
    }
    showWarningToast() {
        this.showToast( 'Warning Title', 'Warning Message', 'warning' );
    }
    showErrorToast() {
        this.showToast( 'Error Title', 'Error Message', 'error' );
    }

    showToast( title, message, variantStr ) {
        const event = new ShowToastEvent({
            title: title,
            message: message,
            variant: variantStr
        });
        this.dispatchEvent(event);
    }
}

In our demo lightning web component we will add 4 buttons – one for each variant of toast notification:

Info Toast Notification:

Success Toast Notification:

Warning Toast Notification:

Error Toast Notification:

How to fix error “Java runtime could not be located. Set one using the salesforcedx-vscode-apex.java.home VS Code setting” in Visual Studio code.

Today I was trying to set up Visual Studio Code on my personal computer and when I tried to create project I received this error: “Java runtime could not be located. Set one using the salesforcedx-vscode-apex.java.home VS Code setting”.

The message is self-explanatory, however it took me few minutes to figure out how to fix it.

What is causing issue?

Current version of Salesforce Extension Pack for Visual Studio Code requires Java Platform, Standard Edition Development Kit 8 (JDK8). If you don’t have it – install it first, you can find it and download it here.

I received this error even though I had JDK8 installed and configured in PATH environment variable to point to the right folder.

How to fix this error?

In Visual Studio Code go to File –> Preferences –> Settings or (Ctrl + comma)

Scroll down and find Salesforce Apex Configuration and on the right side add:

“salesforcedx-vscode-apex.java.home”: “path_to_JDK8”