Salesforce Platform Developer I (legacy) — Question 167
A developer wants to improve runtime performance of Apex calls by caching results on the client.
What is the most efficient way to implement this and follow best practices?
Answer options
- A. Decorate the server-side method with @AuraEnabled(storable=true).
- B. Set a cookie in the browser for use upon return to the page.
- C. Call the setStorable() method on the action in the JavaScript client-side code.
- D. Decorate the server-side method with @AuraEnabled(cacheable=true).
Correct answer: D
Explanation
The correct answer is D because using @AuraEnabled(cacheable=true) allows the results of the server-side method to be cached on the client efficiently, improving performance and following best practices. Options A and C are incorrect as they do not utilize the appropriate caching method for Apex calls, and option B is less efficient compared to the built-in caching provided by Salesforce.