Call Apex Methods

  • Lightning web components can import methods(AuraEnabled) from Apex classes. 
  • The imported methods are functions that the component can call either via @wire or imperatively. 
  • It's a best practice to treat all data that a component receives as immutable.  
  • To mutate the data, make a shallow copy of the objects you want to mutate. 

 

  • Import Apex Methods 
  • Expose Apex Methods to Lightning Web Components 
    • @AuraEnabled 
  • Wire Apex Methods to Lightning Web Components 
    • @AuraEnabled(cacheable=true) 
    •  A client-side LDS cache is checked before issuing the network call to invoke the Apex method on the server. To refresh stale data, call refreshApex(), because Lightning Data Service doesn't manage data provisioned by Apex. 
  • Call an Apex Method with Parameters 
  • Client-Side Caching of Apex Method Results 
    • @AuraEnabled(cacheable=true) 
    • It improves your component's performance by showing cached data from client-side storage without waiting for a server trip. 
    • Wire always need cacheable=true 
    • Imperative call does not mandate cacheable=true 
    • refreshApex() - refreshes cache if the cache data is stale 
    • getRecordNotifyChange(recordIds) - this refreshes the cache when apex method is invoked. 
  • Continuation (Need time to know more) 
  • Secure Apex Classes :  
    • Grant User Access for Apex Classes 
    • Enforce Sharing Rules - with sharing keyword 
    • Enforce Object and Field Permissions (CRUD and FLS) - WITH SECURITY_ENFORCED clause in SOQL 
  • Graceful degradation with stripInaccessible() -  
    • On the Security class, stripInaccessible method. This AuraHandledException if there are any rows which are not supposed to be accessed by user. 
      • This is same as SECURITY_ENFORCED, but we can provide a better error messages to end user. 
      •  

 


Read more on TOI
More from ChatGPT
null

No comments:

Powered by Blogger.