You need to sign in to do that
Don't have an account?
kallam salesforce1
Unable to fetch results, Can someone help what is the issue in this program?
public with sharing class lDS_GetContacts_Wire2 {
@AuraEnabled(cacheable=true)
public static list<Contact> findContacts(string searchtext){
string key = '%'+searchtext+'%';
return [Select id,Name,Phone,Email from Contact where FirstName LIKE:key];
}
}
HTML FILE
<template>
<lightning-card title="Search Contact WIRE">
<lightning-input label="Enter the Search Text" type="search" value={searchkey} onchange={handleOnchange}>
<template if:true={contact.data}>
<template for:each={contact.data} for:item="con">
<p key={con.id}>{con.Name}</p>
</template>
</template>
<template if:true={contact.error}>
Sorry we can't display your record due to {contact.error}. Please Try Later.
</template>
</lightning-input>
</lightning-card>
</template>
Js File >>>>>>>
import { LightningElement,track,wire} from 'lwc';
import findcontacts from '@salesforce/apex/lDS_GetContacts_Wire2.findContacts'
export default class LDS_SearchContact_Wire extends LightningElement {
@track searchkey;
@wire (findcontacts,{searchtext :'$searchkey'}) contact;
handleOnchange(event){
this.searchkey = event.target.value;
}
}
@AuraEnabled(cacheable=true)
public static list<Contact> findContacts(string searchtext){
string key = '%'+searchtext+'%';
return [Select id,Name,Phone,Email from Contact where FirstName LIKE:key];
}
}
HTML FILE
<template>
<lightning-card title="Search Contact WIRE">
<lightning-input label="Enter the Search Text" type="search" value={searchkey} onchange={handleOnchange}>
<template if:true={contact.data}>
<template for:each={contact.data} for:item="con">
<p key={con.id}>{con.Name}</p>
</template>
</template>
<template if:true={contact.error}>
Sorry we can't display your record due to {contact.error}. Please Try Later.
</template>
</lightning-input>
</lightning-card>
</template>
Js File >>>>>>>
import { LightningElement,track,wire} from 'lwc';
import findcontacts from '@salesforce/apex/lDS_GetContacts_Wire2.findContacts'
export default class LDS_SearchContact_Wire extends LightningElement {
@track searchkey;
@wire (findcontacts,{searchtext :'$searchkey'}) contact;
handleOnchange(event){
this.searchkey = event.target.value;
}
}
Try Below Code Please Mark It As Best Answer If It Helps
Thank You!
Hi CharuDutt,
Your code is woring fine but what is the error in my code.