Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create lightning platform show toast event/dispatchEvent where display toast message with hyperlink click button and navigate to external link in Salesforce lightning web component LWC #56

Open
vijayk3327 opened this issue Jul 15, 2023 · 0 comments
Assignees
Labels
documentation Improvements or additions to documentation question Further information is requested

Comments

@vijayk3327
Copy link
Owner

In this post we are going to learn about how to Create lightning platform show toast event/dispatchEvent where display toast message with hyperlink click button and navigate to external link in Salesforce lightning web component LWC

→ Get source code live demo link:-

Step 1:- Create Lightning Web Component : lwcToastEvent.html

`


Show Toast Event and Navigate to RecordPage in Lightning Web Component (LWC)




  <div class="slds-grid slds-wrap">
      <div class="slds-col slds-size_6-of-12">
          <lightning-button variant="brand" label="Show Toast" onclick={showToast}></lightning-button>
        </div>
      <div class="slds-col slds-size_6-of-12">
        <lightning-button variant="brand" label="Navigate External Link" onclick={handleButtonClick}></lightning-button>
     </div>
  </div>
   
   <br/>

`

Step 2:- Create Lightning Web Component : lwcToastEvent.js

` import { LightningElement } from 'lwc';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
export default class LwcToastEvent extends LightningElement {

showToast() {
    const event = new ShowToastEvent({
        title: 'Success',
        message:'Record created has been successfully',
            variant: 'success',
    });
    this.dispatchEvent(event);
}

  
    handleButtonClick() {
        const event = new ShowToastEvent({
            title: 'Success!',
            message: 'Record {0} created! See it {1}!',
            variant: 'success',
            messageData: [
                'w3web',
                {
                    url: 'https://www.w3web.net/',
                    label: 'Click Here',
                },
            ],
        });
        this.dispatchEvent(event);
    }

}`

Step 3:- Create Lightning Web Component : lwcToastEvent.js-meta.xml

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

@vijayk3327 vijayk3327 added documentation Improvements or additions to documentation question Further information is requested labels Jul 15, 2023
@vijayk3327 vijayk3327 self-assigned this Jul 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation question Further information is requested
Projects
Status: No status
Development

No branches or pull requests

1 participant