Hey guys, today in this post we are going to learn about Create Custom Record Search Functionality on Account Object using ‘for:each template’ With Table Rows And Cells In Salesforce Lightning Web Component – LWC.
Files we used in this post example:-
lwcSearchAccountList.html | Lightning Web Component HTML | Template HTML file used to write HTML element for build user interface. |
lwcSearchAccountList.js |
Lightning Web Component JavaScript | It is hold Search function and fetch the account name value from database server. |
lwcSearchAccountList.js-meta.xml |
XML Meta | It is used for where this lightning web component should be exposed. |
lwcSearchAccountList.css | Component Style CSS | It is used for create custom table row border color and padding space. |
lwcApexController.cls | Apex Controller | It is used for Search Account name from database sserver |
Live Demo
Other related post that would you like to learn in LWC
Step 1:- Create Lightning Web Component : lwcSearchAccountList.html
SFDX:Lightning Web Component >> New >> lwcSearchAccountList.html
lwcSearchAccountList.html [Lightning Web Component HTML]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
<template> <lightning-card> <h3 slot="title"> <lightning-icon icon-name="standard:account" size="small"></lightning-icon> Custom Search Functionality on Account Object in LWC. </h3> <p class="slds-p-horizontal_small"> <lightning-input type="search" class="slds-m-bottom_small" label="Search Account Name" onchange={searchAccountAction} value={accountName}></lightning-input> </p> <div class="slds-p-around--medium"> <table border="1" bordercolor="#ddd" cellpadding="5" cellspacing="0" style="border-collapse:collapse;" class="lwsTablePad"> <tr> <th>Name</th> <th>Phone</th> <th>Website</th> <th>Industry</th> <th>Description</th> </tr> <template for:each={accountList} for:item="accObj" for:index="index"> <tr class="slds-hint-parent" key={accObj.Id}> <td>{accObj.Name}</td> <td>{accObj.Phone}</td> <td>{accObj.Website}</td> <td>{accObj.Industry}</td> <td>{accObj.Description}</td> </tr> </template> </table> </div> </lightning-card> </template> |
Step 2:- Create Lightning Web Component : lwcSearchAccountList.js
SFDX:Lightning Web Component >> New >> lwcSearchAccountList.js
lwcSearchAccountList.js [JavaScript Controller]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
import { LightningElement, track, wire } from 'lwc'; import getAccounts from '@salesforce/apex/lwcApexController.searchAccountNameMethod'; const DELAY = 100; export default class LwcSearchAccountList extends LightningElement { accountName = ''; accountPhone = ''; accountWebsite = ''; accountIndustry = ''; accountDescription = ''; @track accountList= []; @wire (getAccounts,{ accStrName:'$accountName', accStrPhone:'$accountPhone', accStrWebsite:'$accountWebsite', accStrIndustry:'$accountIndustry', accStrDescription:'$accountDescription' }) retrieveAccounts({error, data}){ if(data){ this.accountList=data; } else if(error){ } } searchAccountAction(event){ //this.accountName = event.target.value; const searchString = event.target.value; window.clearTimeout(this.delayTimeout); this.delayTimeout = setTimeout(() => { this.accountName = searchString; }, DELAY); } } |
Step 3:- Create Lightning Web Component : lwcSearchAccountList.js-meta.xml
SFDX:Lightning Web Component >> New >> lwcSearchAccountList.js-meta.xml
lwcSearchAccountList.js-meta.xml [LWC Meta Data XML]
1 2 3 4 5 6 7 8 9 10 11 |
<?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> <target>lightning__Tab</target> </targets> </LightningComponentBundle> |
Step 4:- Create Lightning Web Component : lwcSearchAccountList.css
SFDX:Lightning Web Component >> New >> lwcSearchAccountList.css
lwcSearchAccountList.css [LWC Meta Data XML]
1 2 |
.lwsTablePad td, .lwsTablePad th{padding:5px; width: 20%;} .lwsTablePad th{background-color: #eee;} |
Step 5:- Create Lightning Web Component : lwcApexController.cls
SFDX:Create Apex Class >> New >> lwcApexController.cls
lwcApexController.cls [Apex Class]
1 2 3 4 5 6 7 8 9 10 |
public with sharing class lwcApexController { @AuraEnabled(cacheable=true) public static List<Account> searchAccountNameMethod (String accStrName, String accStrPhone, String accStrWebsite, String accStrIndustry, String accStrDescription){ String keyNameString = '%' + accStrName + '%'; return [Select Id, Name, Phone, Website, Industry, Description From Account Where Name like:keyNameString]; } } |
Further post that would you like to learn in LWC
Nice content with good readability. loved it feel free to visit our site take some time and you will get worthy and best content based on technology..
Nice blog…
GET YOUTUBE THUMBNAIL HD
You’re a beautiful inspiration. It really helps me in any situation. Where I stuck. Many of my friends told me to comment there post but I stuck what I should comment. Finally I got your post it always help me. Thanks for the lovely post.
BSEAP SSC Model Paper 2021 Available Students you can Download in Pdf format form this web page below given links. BSEAP Regulaake State Board Exam. They Conduct Board Exams tenth 2021 Session has Been Issued Date Sheet too Assam 10th Class Question Paper 2021 On its Authorized online interface. Get the SEBA HSLC Question Paper 2021 Blueprint in the event that you Want to Score Good Mark.AP SSC Model Paper 2021 At that point each certainly one of you Need to First Understand Question Pattern inside the Right Way. By Assam Board Assam HSLC Previous Question Paper Aspirants Of Class 10th Can Easily Understand the Ratio of the Easy and Difficult Question Asked From Each Unit of the Subject.
Thanks for Sharing such an amazing article. Keep working… Your Site is very nice, and it’s very helping us.. this post is unique and interesting, thank you for sharing this awesome information
Nice and interesting post sir!!! Good Information thanks ….