function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Albert RaulAlbert Raul 

Can you show me example, how to use @wire with function with js, html and apex code?

Arun Kumar 1141Arun Kumar 1141
Hello Albert,
Check out the below code for fetching Bank details from Org:
import { LightningElement, track, wire } from 'lwc';

import getBank from '@salesforce/apex/FetchingBankDetails.getBank';

export default class CustomClass extends LightningElement {

@track searchKey;

@track mybank;

@track error;

@wire (getBank,{text:'$searchKey'})

wiredBanks({data, error}){


    this.mybank = data;

    this.error = undefined;



    this.mybank = undefined;

    this.error = error;




   this.searchKey =;



Apex Code
public with sharing class FetchingBankDetails {


 public static List<Bank__c> getBank(String text){

    List<Bank__c> bList = [SELECT id, Name, Bank_Name__c FROM Bank__c WHERE Name LIKE :'%'+text+'%'];
    return bList;

Html Code


    <b>CA Bank with function</b>


     <lightning-input label="My Bank Details" onchange={handlemyBank}></lightning-input>

       <template if:true={mybank}>

         <template for:each={mybank} for:item="b">

           <lightning-layout key={b.Id}>









If you find this helpful, please mark it as the best answer.
Thank you.
Albert RaulAlbert Raul
Hey thanks arun
SubratSubrat (Salesforce Developers) 
Hello Albert ,

Here's an another example of how you can use the @wire decorator in JavaScript, along with Apex code and HTML markup.

HTML Markup (example.html):
  <lightning-card title="User Information">
    <div class="slds-p-around_medium">
      <template if:true={}>
          <p>First Name: {}</p>
          <p>Last Name: {}</p>
          <p>Email: {}</p>
      <template if:false={}>
        <p>Loading user information...</p>

JavaScript Code (example.js):
import { LightningElement, wire } from 'lwc';
import getUserInfo from '@salesforce/apex/UserController.getUserInfo';

export default class ExampleComponent extends LightningElement {
  @wire(getUserInfo) user;

Apex Code (UserController.cls):
public with sharing class UserController {
    public static User getUserInfo() {
        return [SELECT Id, FirstName, LastName, Email FROM User WHERE Id = :UserInfo.getUserId()];
In this example, we have an LWC component (ExampleComponent) that uses the @wire decorator to fetch user information from the getUserInfo Apex method. The user information is then displayed in a Lightning Card component in the HTML template.

The getUserInfo method in the Apex controller retrieves the user's first name, last name, and email based on the current user's ID.

Note that you need to make sure that the Apex method is marked as @AuraEnabled and cacheable=true to leverage the @wire functionality.

If the above example helps , please mark this as Best Answer.
Thank you.