What is the purpose of the AuraEnabled annotation and its parameters?
Suggested answer
The @AuraEnabled annotation exposes an Apex method to be called from LWC or Aura components. Parameters: cacheable=true: The method's results can be cached by the browser (Lightning Data Service cache). Required for using the method with @wire. Cacheable methods must be read-only (no DML or side effects — enforced by the platform). cacheable=false (default): Used for methods with DML or side effects. Cannot be used with @wire — only imperative calls. The method must be public or global static. Return types must be JSON-serialisable (primitives, sObjects, Lists, Maps with String keys, custom Apex classes with public/global fields). Exceptions thrown in @AuraEnabled methods are surfaced as AuraHandledExceptions in the component — always throw new AuraHandledException(e.getMessage()) for clean error handling.
Practice content for interview preparation; not an official vendor answer. Verify details against current product documentation.
Community comments (0)
No comments yet.
Sign in or create a free account to add a comment. Comments are moderated before they appear.