Salesforce Developer Interview questions LWC

Can we call the @AuraEnabled function in the apex class using wire ? 

Ans: Function also needs to have cacheable = true  annotation ie should be like @AuraEnabled(cacheable = true)

What do you mean by  cacheable = true annotations ? 
Ans: First of all when you mark function as cacheable = true it can only retrieve data i.e. it cant have any DML.
It is used to improve component performance by quickly showing cached data from client side storage without waiting for server trip.
Remember to refresh the stale data provisioned by Apex we have to use refreshApex as LDS doesn’t manage data coming from Apex ( In case of wired service)

  1. Why do we use $ when passing property in wire function, what does it mean? [Latest Salesforce lightning interview questions and answeres]
    Ans: $ prefix tells the wire service to treat values passed as a property of the class and evaluate it as this.propertyName and the  property is reactive. If the property’s value changes, new data is provisioned and the component renders.
  2. When is the wire method/property called in the lifecycle of a component ?
  3. Ans: Wired service is called right after component is created ie after constructor and is again called when parameter that you are passing is made available.


Comments