Implementing Custom Record Search Functionality With Lightning Web Components (LWC)

Custom Record search Functionality Using Lightning Web Component LWC 

The Blog Post will show how to Create Custom Record Search Functionality on Account Object using Lightning Web Component i.e LWC

Please Follow the Below step.

Step 1:- Create Apex Class for Account search.

public class vlog_AccountSearch {
    @AuraEnabled(Cacheable = true)
    public static list<Account> getAccountData(String textkey) {
        textkey = '%' + textkey + '%';
        list<Account> accLst = [SELECT  Id, Name, Industry, Phone, Type From Account WHERE Name LIKE :textkey];
        if(accLst.isEmpty()) {
            throw new AuraHandledException('No Record Found..');
        return accLst; 

Step 2:- Create HTML component for Account search.

    <lightning-card title="Custom Account Search">
        <lightning-layout multiple-rows="true" vertical-align="end">
            <lightning-layout-item size="4" padding="around-small">
                 <!--Input text to Search Account-->
                <lightning-input type="text" label="Enter Account Name To Search"
            </lightning-layout-item >

            <lightning-layout-item size="2" padding="around-small">
                <!--Search Button-->
                <lightning-button label="Search" variant="brand" onclick={SearchAccountHandler}>

            <lightning-layout-item size="12" padding="around-small">
                <!--List Of Account Using data Tabel-->
                <lightning-datatable key-field="id" data={accounts} columns ={cols}> 


Step 3:- Create a Javascript controller for Account search.

import { LightningElement, track } from 'lwc';
import getAccountData from '@salesforce/apex/vlog_AccountSearch.getAccountData';

export default class CustomRecordSearch extends LightningElement {
    @track accounts;
    //This Funcation will get the value from Text Input.
        this.searchKey =;

    //This funcation will fetch the Account Name on basis of searchkey
        //call Apex method.
        getAccountData({textkey: this.searchKey})
        .then(result => {
                this.accounts = result;
        .catch( error=>{
            this.accounts = null;

    cols = [
        {label:'Account Name', fieldName:'Name' , type:'text'} ,
        {label:'Phone', fieldName:'Phone' , type:'Phone'} ,
        {label:'Industry', fieldName:'Industry' , type:'text'}

Step 4:- Create Meta.xml for visibility of web component.

<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="">