function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
bheemudu neelibheemudu neeli 

I need a help on auto search functionality sample code

Hello All,
I need a help on auto search functionality sample code  as input value, so that i can use that field value to assign to other field.

Thank you,
Bheem
 
SwethaSwetha (Salesforce Developers) 
HI Bheem,
Recommend reviewing the below links to get started:
http://blogforce9.blogspot.com/2013/10/auto-complete-visualforce-component-v2.html
https://salesforce.stackexchange.com/questions/153718/how-to-enable-autocomplete-feature-of-lookup-inputfield-with-lookup-filter
https://developer.salesforce.com/forums/?id=906F0000000AMC9IAO
https://sfdchack.blogspot.com/2013/04/search-records-in-salesforce-using-auto.html

If this information helps, please mark the answer as best. Thank you
CharuDuttCharuDutt
Hii Bheemudu
Try Below Code
LWC
<div>        
            <lightning-input type="search" onchange={handleChange} class="slds-m-around_medium" label="Search">  
            </lightning-input>  
        </div>
        <table class="slds-table slds-table_cell-buffer slds-table_bordered">
            <thead>
                <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="Parent Account">Parent Account</div>
                  </th>
                  <th class="" scope="col">
                    <div class="slds-truncate" title="Type">Industry</div>
                  </th>
                  <th class="" scope="col">
                    <div class="slds-truncate" title="Rating">Rating</div>
                  </th>
                  <th class="" scope="col">
                    <div class="slds-truncate" title="Phone">Phone</div>
                  </th>
                  <th class="" scope="col">
                    <div class="slds-truncate" title="Ownership">Ownership</div>
                  </th>
                </tr>
              </thead>
              <tbody>
                <template for:each={records} for:item ='record'>
                <tr class="" key = {record.Id}>
                        <td data-label="Account Name">
                            <div class="slds-cell-wrap"><a href="javascript:void(0);">{record.Name}</a></div>
                        </td>
                        <td data-label="Parent Account">
                            <div class="slds-cell-wrap"><a href="javascript:void(0);">{record.ParentId}</a></div>
                        </td>
                        <td data-label="Industry">
                            <div class="slds-cell-wrap">{record.Industry}</div>
                        </td>
                        <td data-label="Rating">
                            <div class="slds-cell-wrap">{record.Rating}</div>
                        </td>
                        <td data-label="Phone">
                            <div class="slds-cell-wrap">{record.Phone}</div>
                        </td>
                </tr>
                </template>
            </tbody>
        </table>



JS
import { LightningElement,api,track,wire } from 'lwc';
import getAllAccounts from '@salesforce/apex/TestTable.getAllAccounts';
export default class testTable extends LightningElement {
    @api records;
    @api errors;
    @track Name;

    handleChange(event){
        var sVal = event.target.value;
        this.Name = sVal;
    }

    @wire(getAllAccounts,{
        Name :  "$Name"}
    )
    wiredCases({
        data,error
    }){
    if(data){
        this.records = data;
        this.errors = undefined;
    }
    if(error){
        this.errors = error;
        this.records = undefined;
        }
    }
}


Apex
public class customTable {
 @AuraEnabled(cacheable = true)
    public static List<Account> getAllAccounts(String Name){
        system.debug('Name===> ' + Name);
        String key = '%' + Name + '%';
        List<Account> accList =[Select Id,Name,Ownership,
                                Industry,Rating,ParentId,Phone FROM Account WHERE Name LIKE : key];
        return accList;
    }
}
Please Mark It As Best Answer If It Helps
Thank You!