I have search input box on searching the account names in the input box it should display the list of account names but i am unable to see the result i inspected my code but don't see any issues. Can you help me what is the issue.
public with sharing class AccountController {
@AuraEnabled(cacheable=true)
public static List<Account> findAccounts(String searchKey){
String key = '%' + searchKey + '%';
return [SELECT Id, Name, Type, Industry FROM Account WHERE Name LIKE :key LIMIT 5];
}
}
Apexdemo.html
<template>
<lightning-card title="Apex Wire To Property Demo">
<div class="slds-p-around_medium">
<lightning-input type="search"
label="Search Account" value={searchKey}
onchange={searchHandler}>
</lightning-input>
</div>
<template if:true={accounts}>
<template for:each={accounts} for:item="account">
<div class="slds-box slds-box_xx-small" key={account.Id}>
<p>Name -{account.name}</p>
<p>Type -{account.Type}</p>
<p>Industry -{account.Industry}</p>
</div>
</template>
</template>
</lightning-card>
</template>
Apexdemo.js file :
import { LightningElement } from 'lwc';
import findAccounts from '@salesforce/apex/AccountController.findAccounts'
export default class ApexImperativeDemo extends LightningElement {
searchKey=''
accounts
timer
searchHandler(event){
window.clearTimeout(this.timer)
this.searchKey = event.target.value
this.timer = setTimeout(()=>{
this.callApex()
}, 1000)
}
callApex(){
findAccounts({searchKey:this.searchKey})
.then(result=>{
this.accounts = result
}).catch(error=>{
console.error(error)
})
}
}
list<Account>
in your apex controller. Also instead of writing justaccounts
use@track accounts=[];
in your js file