Salesforce Certified Platform Developer II — Question 117
A developer is using a third-party JavaScript library to create a custom user interface in Visualforce. The developer needs to use JavaScript to get data from a controller method in response to a user action.
How can the developer accomplish this?
Answer options
- A. Use <apex:actionFunction> to create a JavaScript wrapper for the controller method
- B. Use the @RemoteAction annotation on the method definition with JavaScript Remoting
- C. Use the $Controller global variable to access the controller method via JavaScript
- D. Use <apex:actionSupport> to enable JavaScript support for the controller method
Correct answer: B
Explanation
The correct answer is B, as the @RemoteAction annotation allows the developer to call the controller method from JavaScript, enabling seamless data retrieval. Option A is incorrect because <apex:actionFunction> is not specifically designed for JavaScript Remoting. Option C is wrong as the $Controller global variable does not directly allow access to controller methods via JavaScript. Option D, while related to JavaScript support, does not specifically enable data retrieval like option B does.