How to display the data in Lightning Web Component
Video link
========
https://www.youtube.com/watch?v=lnE2z9ZfMfc&t=80s
displayContacts.html
====================
<template>
<template for:each={contacts.data} for:item="con">
<p key={con.Id}>
{con.LastName}
</p>
</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;
}
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;
}
}
Good Post. I like your blog. Thanks for Sharing
ReplyDeleteSalesforce Custom Application Development Services