Hai Omkar,
I have tried this, how Amey suggested. You can find the below code.
CMP.file
<template>
<lightning-input label="Enter Email" onchange={handleemailvalue}></lightning-input><br>
<lightning-button label="Search" onclick={handleCheck}></lightning-button>
</template>
Js.file
import { LightningElement,api,wire,track} from 'lwc';
import checkinContact from '@salesforce/apex/contactclass.checkinContact';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
export default class Fecthemail extends LightningElement {
@api enteredEmail;
handleemailvalue(event) {
this.enteredEmail = event.detail.value;
}
handleCheck(){
checkinContact({conEmail : this.enteredEmail})
.then(result => {
if(result === true){
const event = new ShowToastEvent({
title: 'Contact Found',
message: 'Found contact with same Email',
variant: 'success'
});
this.dispatchEvent(event);
}
else{
const event = new ShowToastEvent({
title : 'Contact Not Found',
message : 'Did not found contact with the email you have entered',
variant : 'error'
});
this.dispatchEvent(event);
}
})
}
}
Apex Class:-
public class contactclass {
@AuraEnabled(Cacheable = true)
public static Boolean checkinContact(string conEmail){
Boolean bool = false;
List<Contact> con = [SELECT id,Name,Email FROM Contact where Email =:conEmail];
if(con.size()>0){
bool = true;
}
else{
bool = false;
}
system.debug(bool);
return bool;
}
}
If you found this is helpful, please make this answer correct. And also if anyone is interested to see some component development in lightning you can check my blog.
Thanks,
Mithun
2 answers