How to get the selected RecordId in Lightning Web Component
Video link
========
https://www.youtube.com/watch?v=7VDPA8S7Uss&t=23s
displayContacts.html
====================
<template>
<template for:each={contacts.data} for:item="con">
<p key={con.Id}>
{con.LastName}
</p>
<lightning-button label="Click me" variant="brand" onclick={handleClick} value={con.Id}>
</lightning-button>
</template>
<template if:true={contacts.error}>
Error in processing the data
</template>
</template>
displayContacts.js
==================
import { LightningElement,wire} from 'lwc';
import getAllContacts from '@salesforce/apex/ContactController.getAllContacts';
export default class DisplayContacts extends LightningElement
{
@wire(getAllContacts) contacts;
handleClick(event)
{
const currentId=event.target.value;
alert('====CurrentRecordId is===='+currentId);
}
}
Apex class
==========
public with sharing class ContactController
{
@AuraEnabled(cacheable=true)
public static List<Contact> getAllContacts()
{
List<Contact> conlist=[select LastName,Email,Phone from Contact LIMIT 5];
return conlist;
}
}
Comments
Post a Comment