Showing posts with label Lightning. Show all posts
Showing posts with label Lightning. Show all posts

Wednesday, 30 January 2019

Toast Notification in Lightning Web Components | ShowToastEvent | (LWC)


Lets talk about how to fire Toast Notification in Lightning web component | LWC. Toast message is used to pop up the alert message to user. To display toast notification you need to import the ShowToastEvent from lightning/platformShowToastEvent module and dispatch the ShowToastEvent event with message , title and variant.

Syntax 

ShowToastMessage() {
     const toastEvnt = new  ShowToastEvent( {
           title: 'Welcome in Apex Hours',
           message: 'This is your toast message',
           variant: 'info',
     });
     this.dispatchEvent (toastEvnt);

}


Here is sample code:-

toastMessage.html
<template>
    <lightning-card title="Show Toast Message" icon-name="custom:custom56">
        <lightning-input label="Message" value={msg} onchange={msgchange}></lightning-input>
        <lightning-button label="Show Toast Message" onclick={ShowToastMessage}></lightning-button>
    </lightning-card>
</template>


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

export default class ToastMessage extends LightningElement {
    msg = '';
    msgchange(event){
        this.msg = event.target.value;
    }
    ShowToastMessage() {
        const toastEvnt = new  ShowToastEvent( {
              title: 'Welcome in Apex Hours' ,
              message: this.msg ,
              variant: 'success' ,
        });
        this.dispatchEvent (toastEvnt);
   }
}


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


Output


Check this post for more detail.

Please check below post on Lightning Web Components:-
  1. Lightning Web Components ( LWC ) in Salesforce with Non-Scratch Org
  2. Invoke Apex Controller from Lightning Web Component | Lightning Web Component inside Another LWC
  3. Design attributes in Lightning Web Components | CSS and SVG Files | Lightning Web Components | targetConfigs
  4. How to get current user id in lightning web component | Access logged in user ID in LWC

Check our YouTube Channel for more recording in Lightning Web Components. 

Thanks,
Amit Chaudhary
amit.salesforce21@gmail.com

Friday, 11 January 2019

How to get current user id in lightning web component | Access logged in user ID in LWC


 To get current user id in LWC we need to import the "@salesforce/user/Id" Salesforce module.

 Syntax :-
import userId from '@salesforce/user/Id';

Sample Code :-

 showUserId.html
<template>
    <lightning-card title="Show User Detail" icon-name="custom:custom15">
        <div class="slds-m-around_medium">
            <p>User Id: {userId} </p>
        </div>
    </lightning-card>
</template>

 showUserId.js
import { LightningElement } from 'lwc';
import strUserId from '@salesforce/user/Id';

export default class ShowUserDetail extends LightningElement {
    userId = strUserId;
}

 showUserId.js-meta.xml
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata" fqn="ShowUserDetail">
    <apiVersion>45.0</apiVersion>
    <isExposed>true</isExposed>

    <targets>
        <target>lightning__AppPage</target>
        <target>lightning__RecordPage</target>
        <target>lightning__HomePage</target>
    </targets>

</LightningComponentBundle>

Output :-



Please check our old post on Lightning Web Components:-
Feel free to post your feedback or question.

Thanks,
Amit Chaudhary

Wednesday, 9 January 2019

Design attributes in Lightning Web Components | CSS and SVG Files | Lightning Web Components | targetConfigs



In our last post we talk about How to create first lightning web components and How to invoke apex class from Lightning web components. In this post we will talk about how to create design attribute in lightning web components.

We know how to create Design Attribute in lightning component. For Design Attribute we used to create <design:attribute tag in design file. But for Lightning web components we need to define the design attribute in Component Configuration File (XML) with<targetConfigs> tag. The component author need to defines the property in the component’s JavaScript class using the @api decorator.


We can use Design Attribute to make lightning web components attribute available to System Admin to edit Lightning App Builder or Community. 

Here is Sample code.

HelloWorld.html
<template>
    <lightning-card title={strTitle} icon-name="custom:custom14">
        <div>
            <p>  Hello , {firstName} </p>
        </div>
        <div>
            <template if:true={showImage}>
                <img src={imgUrl} width="200" height="200"/>
            </template>
        </div>
    </lightning-card>
</template>


HelloWorld.js
import { LightningElement, api } from 'lwc';
export default class MyComponent extends LightningElement {
    @api firstName ='Amit';
    @api strTitle ='Welcome in Salesforce';
    @api showImage =false;
    @api imgUrl ='';
}

HelloWorld.js-meta.xml
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata" fqn="MyComponent">
    <apiVersion>45.0</apiVersion>
    <isExposed>true</isExposed>

    <targets>
        <target>lightning__AppPage</target>
        <target>lightning__RecordPage</target>
        <target>lightning__HomePage</target>
    </targets>

    <targetConfigs>  
        <targetConfig targets="lightning__HomePage,lightning__RecordPage">
            <property name="strTitle" type="String" default="Welcome in Salesforce" label="Enter the title"/>
            <property name="showImage" type="Boolean" default="true" label="Show Image ?"/>
            <property name="imgUrl" type="String" default="" label="Enter Image URL"/>
        </targetConfig>
    </targetConfigs>
   
</LightningComponentBundle>

Define the design Attribute in <property tag under <TargetConfig tag.

Please check our YouTube Channel Recording for same topic.

https://www.youtube.com/watch?v=oDj8R8QZdrg&t=1159s




 Please check our old post on Lightning Web Components:-
 
Feel free to post your feedback or question.

Thanks,
Amit Chaudhary

Capture.JPG  @amit_sfdc    #SalesforceApexHours    @ApexHours
  Salesforce Apex Hours


Monday, 7 January 2019

How to setup salesforce customer community | Setup and manage salesforce communities

How to setup salesforce customer community


Long time back we create one post of "How to setup salesforce community". In this post we will talk about step by step process to setup salesforce community. We will cover below topics:-

1) Introduction to Community Cloud.

2) How to create Basic Salesforce Community with Community Builder.
3) How to create the Custom Content Layout with Lightning Component.
4) How to setup Salesforce Navigation Menu.
5) How to setup page Variations and audience in Lightning Salesforce Community.
6) How to setup/configure Snap-in Chat.
7) How to create Lightning Bolt Solution.


1) Introduction to Community Cloud

Get to know about what is community cloud and how many type of community cloud license we have.


2) Setup Salesforce Community 

In this recording we talk about how to setup Salesforce lightning community and how to configure the community Theme, change color / font and Upload the community header/ banner image. We also talk about how to setup self registration in community.


3) Content Layout in Salesforce Community

In this recording we talk about how to create custom content layout for your Salesforce community.


4) Setup Communities Navigation Menu

In this recording we talk about how to create navigation menu/sub menu for your Salesforce community.

5) Page Variations and Audience in Salesforce Community

Audiences are sets of criteria used to define community member. Use them to keep your community members engaged by offering them personalized, relevant content. We can also create page variations that target specific audiences community (base on location, profile etc), and control who sees which page base on their profile and audiences criteria. Please check below recording for step by step process to setup page variations and audience in salesforce community.


6) Knowledge In Community

In this recording we can see how to configure the Knowledge and how to configure the Content / Articles for your Salesforce community.



7) Snap in Chat in Salesforce Community 

If you want to configure the Live agent with Snap-in Chat then check below recording. In below recording we talk about step by step process to configure the Snap-in Chat.



8) Lightning Bolt Solution

In out last post we talk about Lightning Bolt Solution.
Lightning Bolt - new framework for deploying next generation communities and portals quicker. Lightning Bolt for Salesforce allows you to quickly build and distribute industry-specific Lightning Bolt Solutions to jump-start new org capabilities. Save time by building once then reusing

If you want to create the Lightning Bolt Solution. Please check below recording.



Please share your feedback and let us know if you want to learn some new topic in Salesforce Community.


Thanks,
Amit Chaudhary
amit.salesforce21@gmail.com