import { LightningElement, wire } from 'lwc';
import getContacts from '@salesforce/apex/ContactLWCController.getContacts';
export default class ContactList extends LightningElement {
contacts;
@wire(getContacts)
wiredContacts({ error, data }) {
if (data) {
this.contacts = data;
} else if (error) {
console.error('Error fetching contacts:', error);
}
}
}
public with sharing class ContactLWCController {
//@AuraEnabled annotation marks the Apex method as accessible to Lightning components (LWC, Aura components).
@AuraEnabled(cacheable=true)
public static List getContacts() {
return [SELECT Id, Name FROM Contact LIMIT 10];
}
}