Salesforce Certified Platform Developer II free question 5 / 10 · Domain 3: User Interface
In a click handler of an Aura component, three Apex actions are queued one after another with $A.enqueueAction. Which statement about how the requests are sent to the server matches the Developer Guide?
- The queued actions are sent when the user reloads the page
- When the third is queued, the first two are cancelled and only the last one is sent
- A separate request is sent for each action at the moment enqueueAction is called
- At the end of the event loop, the queued actions are sent batched into one or more requests
Show the answer and explanation
Answer: D
Why this is correct
The "Calling a Server-Side Action" page says $A.enqueueAction(action) adds the server-side controller action to the queue of actions to be executed, and that all actions that are enqueued will run at the end of the event loop. Rather than sending a separate request for each individual action, the framework processes the event chain and batches the actions in the queue into one request. The actions are asynchronous and have callbacks.
Why the other options are wrong
"A separate request is sent for each action at the moment enqueueAction is called" … Queued actions run at the end of the event loop. The page says the framework batches them rather than sending a separate request for each individual action.
"When the third is queued, the first two are cancelled and only the last one is sent" … The page describes no cancelling of earlier queued actions. All the actions in the queue are batched into the request.
"The queued actions are sent when the user reloads the page" … The queued actions run at the end of the event loop, not at a page reload.
If an action doesn't run
If your action isn't executing, make sure you're not running code outside the framework's normal rendering lifecycle. For example, if you use window.setTimeout() in an event handler to run logic after a delay, wrap your code in $A.getCallback(). You don't need it when your code runs as part of the framework's call stack, such as handling an event or in the callback for a server-side action.