Posts

How to Use Wrapper Class In Lightning WebComponent

Image
Apex Class
==========
public  class ContactController
{
    @AuraEnabled(cacheable=true)
    public  static List<WrapperClass> displayConRecords()
    {
        List<WrapperClass> wrapperConList=new List<WrapperClass>();
        for(Contact con:[select Id,LastName,Email,Phone from Contact LIMIT 10])
        {

            WrapperClass wrap=new WrapperClass();
            wrap.LastName=con.LastName;
            wrap.Email=con.Email;
            wrap.Phone=con.Phone;
            wrapperConList.add(wrap);
        }
        return wrapperConList;
    }
    public class WrapperClass
    {
        @AuraEnabled
        public String LastName;
        @AuraEnabled
        public String Email;
        @AuraEnabled
        public String Phone;

    }
  }

displayContacts.html
====================
<template>
    <table class="slds-table slds-table_cell-buffer slds-table_header-hidden">
        <tr>
            <th>Name</th>
            <…

How to pass the user input from Child to Parent in Salesforce LWC

Image
video link
=======
https://www.youtube.com/watch?v=Hh3nEIk9sws&t=227s

childComponent.html
===================
<template>
    <lightning-input type="text"  style="width:15%;" label="FirstName" placeholder="Enter the FirstName"  onchange={handleChangeFirstName}>
    </lightning-input>
</template>

childComponent.js
=================
import { LightningElement,api } from 'lwc';
export default class ChildComponent extends LightningElement {
    @api firstname;
    handleChangeFirstName(event){
        this.firstname=event.target.value;
        const sampleEvent=new CustomEvent('inputcarryevent',{
            detail:this.firstname
        });
        this.dispatchEvent(sampleEvent);
    }

}

parentComponent.html
====================
<template>
    <c-child-component oninputcarryevent={handlechange}>
    </c-child-component>
    FirstName is:{firstname}
</template>

parentComponent.js
===…

How to display the records based on selected picklist value with event in LWC

Image
Apex class
==========
public class AccountSearchController
{
    @AuraEnabled(cacheable=true)
    public static List<Account> displayAccountRecords(String searchKey)
    {
        System.debug('searchKey'+searchKey);
        List<Account> returnlist=new List<Account>();
        for(Account acc:[select Name,Industry from Account where Industry=:searchKey])
        {
            returnlist.add(acc);
        }
        return returnlist;
    }
}

childComponent.html
===================
<template>
    <template if:true={IndustryPicklistValues.data}>
        <lightning-combobox name="progress"
           label="Industry"
           value={value}
           placeholder="-Select-"
           options={IndustryPicklistValues.data.values}
           onchange={handleChange} >
        </lightning-combobox>
       </template>
</template>

childComponent.js
=================
import { LightningElement,wire,api …

How to pass the value from one Component to other Component with event in LWC

Image
Video link
=========
https://youtu.be/W9-ANZgxXZI


Apex Class
==========
public with sharing class AccountDemoController {
    public AccountDemoController() {
    }
    @AuraEnabled(cacheable=true)
    public static List<Account> displayAcntRecords(){
        List<Account> acclist=[select Id,Name from Account LIMIT 5];
        return acclist;
    }
    @AuraEnabled(cacheable=true)
    public static List<Contact> displayConRecords(String accId){
        System.debug('@@AccountId@@'+accId);
        List<Contact> conlist=[select Id,LastName,AccountId from Contact where AccountId=:accId];
        return conlist;
    }
}

childComp2.html
===============
<template>
<b>Accounts</b>
    <table class="slds-table slds-table_cell-buffer slds-table_bordered slds-m-top_small">
        <tr>
            <th>Select</th>
            <th>AccountName</th>
        </tr>
        <template for:each={accoun…

How to delete the records with a button in LWC

Image
Video link
========
https://www.youtube.com/watch?v=7rXycIcjHPM&t=71s

Apex Class
==========
public with sharing class AccountCls
{
    @AuraEnabled(cacheable=true)
    public static List<Account> displayAccounts()
{
        List<Account> acclist=[select Id,Name from Account LIMIT 10];
        return acclist;
}
}

deleteAccountsData.html
=======================
<template>
    <template if:true={accounts}>
        <table class="slds-table slds-table_cell-buffer slds-table_header-hidden">
<thead class="slds-assistive-text">
<tr class="slds-line-height_reset">
  <th class="" scope="col">
<div class="slds-truncate" title="Account Name">Account Name</div>
  </th>
  <th class="" scope="col">
<div class="slds-truncate" title="Action">Action</div>
  </th>
</tr>
</thead>
<template for:each={ac…

How to display the records based on selected picklist value in LWC

Image
AccountSearchController
=======================
public class AccountSearchController
{
    @AuraEnabled(cacheable=true)
    public static List<Account> displayAccountRecords(String searchKey)
    {
        System.debug('searchKey'+searchKey);
        List<Account> returnlist=new List<Account>();
        for(Account acc:[select Name,Industry from Account where Industry=:searchKey])
        {
            returnlist.add(acc);
        }
        return returnlist;
    }
}


displayAccounts.html
====================
<template>
<template if:true={IndustryPicklistValues.data}>
<lightning-combobox name="progress"
  label="Industry"
  value={value}
  placeholder="-Select-"
  options={IndustryPicklistValues.data.values}
  onchange={handleChange} >
</lightning-combobox>
</template><br/><br/>
<template if:true={records}>
<table>
  <tr>
<th>AccountName</th>
<th>Industry</th>
 …

How to display the Contacts based on Account Name in Lightning WebComponent

Image
Video link
=========
https://www.youtube.com/watch?v=IkKFPHy29FU&t=16s
Apex Class
==========
public with sharing class AccountController {

    @AuraEnabled(cacheable=true)
    public  static List<Account> getAccounts()
    {
        List<Account> acclist=[select Id,Name from  Account LIMIT 5];
        return acclist;

    }
    @AuraEnabled(cacheable=true)
    public static List<Contact> getAllContacts(String searchKey)
    {
        System.debug('Entered into contact method');

        List<Contact> returnconlist=new List<Contact>();
        for(Contact con:[select LastName,Account.Name from Contact where Account.Name=:searchKey])
        {
            returnconlist.add(con);
            System.debug('Contact list size'+returnconlist);

        }
        if(returnconlist.isEmpty())
        {
            System.debug('No Records found'+returnconlist.size());
        }
        return returnconlist;
    }
}


contactsSearch.html
=====…