Using Wire Apex
Using
Wire Apex
Scenario 1: Using Wire Apex: 
AccountCountroller.html
<template>
    <lightning-card title='Account'>
        <ul>
        <lightning-card title="Account List">
            <div class="slds-m-around_medium">
                <template if:true={accounts.data}>
                    <template for:each={accounts.data} for:item="acc">
                        <p key={acc.Id}>{acc.Name}</p>
                    </template>
                </template>
            </div>
        </lightning-card>
        </ul>
    </lightning-card>
</template>
JS
 import { LightningElement , wire } from 'lwc';
import getAccountList from '@salesforce/apex/AccountController.getAccountList';
export default class AccountCard extends LightningElement {
    @wire(getAccountList) accounts;
    accounts;
    /* 
    Using wire method
        ---- ---shift alt A shortcut ------------
       */
      @wire(getAccountList) accounts;
      accounts;
 }
public with sharing class AccountController {
   @AuraEnabled(cacheable=true)
    public static List<Account> getAccountList() {
      return [SELECT Id, Name,  Phone FROM Account  LIMIT 10];
    }
}
o/p 
displays 10 Account Names
x
Comments
Post a Comment