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(getAccountListaccounts;
    accounts;

    /* 
    Using wire method
        ---- ---shift alt A shortcut ------------
       */
      @wire(getAccountListaccounts;
      accounts;
 }

public with sharing class AccountController {
   @AuraEnabled(cacheable=true)
    public static List<AccountgetAccountList() {
      return [SELECT IdName,  Phone FROM Account  LIMIT 10];
    }
}


o/p
displays 10 Account Names


x

Comments

Popular posts from this blog

Lightning Grid Custom Datatable

Comparing Two Values Using Aura If

Dynamic Standard Datatable Using Fieldset