Sunday, September 24, 2023
HomeUncategorizedSalesforce | Name the Apex Methodology Imperatively in Lightning Internet Part?

Salesforce | Name the Apex Methodology Imperatively in Lightning Internet Part?


After we wish to management when a technique ought to be invoked (as an example, in response to a button click on), we use an crucial methodology name. 

We solely get one response after we name a technique imperatively. 

With @wire, alternatively, it cedes authority to the framework and causes the provisioning of a stream of values. 

Annotate the Apex methodology with @AuraEnabled(cacheable=true) if you wish to make the most of @wire to name it. Earlier than making a community name to the server to name the Apex methodology, a client-side Lightning Knowledge Service cache is checked. 

The next conditions require you to contact an Apex methodology immediately, relatively than by way of @wire. 

  • To invoke any methodology that inserts, modifies, or deletes information and is not tagged with cacheable=true. 
  • To manage when the invocation takes place. 
  • To work with objects like Job and Occasion that Person Interface API doesn’t present. 
  • Utilizing an ES6 module’s methodology name that doesn’t lengthen LightningElement 

dont miss out iconRemember to take a look at: Learn All About the Batch Apex in 2023

Earlier than making a community request to the server to name an Apex methodology tagged with @AuraEnabled(cacheable=true), the client-side Lightning Knowledge Service cache is examined. Nevertheless, Apex-provisioned information is just not managed by Lightning Knowledge Service. Consequently, to replace the Lightning Knowledge, execute getRecordNotifyChange() after calling the Apex methodology. 

Allow us to perceive with a easy example- 


    <lightning-card title="Imprerative Demo"> 
        <div fashion="top: 200px"> 


import { LightningElement,monitor } from 'lwc'; 
import  getCntDetails from '@salesforce/apex/ImperativeMethods.getCntDetails'; 
const columns=[ 
    {label:"Contact Id",fieldName:"Id"}, 
    {label:"Contact Name",fieldName:"Name"}, 
    {label:"Account Name",fieldName:"AccountId"}, 
export default class ImperativeMethod extends LightningElement { 
    @monitor columns=columns; 
    @monitor information=[]; 
        .then(consequence =>{ 
            .catch(error =>{ 
                console.log("error occurd"); 

dont miss out iconTry one other superb weblog by Narendra Kumar right here: Navigation Service in Lightning Web Component | All You Need to Know


<?xml model="1.0" encoding="UTF-8"?> 
<LightningComponentBundle xmlns="http://cleaning"> 


public with sharing class ImperativeMethods { 
    public static listing<Contact> getCntDetails() { 
        listing<Contact>contactDetails=[select Id,Name,AccountId from Contact]; 
        return contactDetails; 




Source link



Please enter your comment!
Please enter your name here

- Advertisment -

Most Popular

Recent Comments