Salesforce Interview Questions & Answers Book is now available!

Grab Now

LWC

Can we import Apex variables from LWC?

Is it possible to import Apex variables from Apex class into LWC? Let's check out.

By Teja, ex-Salesforce engineer · Updated January 20, 2021 · 1 min read

By know you would have known that we can import Apex methods into LWC either using @wire operator or imperatively.

That gets us to the next question, can we import Apex variables from Apex classes into LWC (as shown below)?

@AuraEnabled
public String accountName;
import { LightningElement, wire } from "lwc";

import accountName from "@salesforce/apex/AccountController.accountName";

export default class VzWireApexController extends LightningElement {
  
}

Take a guess before I reveal the suspense!

Am still waiting for your answer :p

Okay let me tell you my version! No, we cannot import Apex variable from Apex class.

Learn it by building it

Every course, every code repository, the discussion group and certificates of completion — one subscription.

Keep me in the loop!

Email me when a new episode is published (promise, I will not spam you)

You're signing up to receive emails from Salesforce Casts