1

On a Lightning Component, when calling an action on the Apex back-end using $A.enqueueAction(...), it takes a whileee to complete (up to 30 secs!). The action in the back-end is just a simple DML.

By reading the docs and inspecting the browser network debug logs, we understand this is because the actions are hold in a queue till some sort of poller/spooler thread processes it and dispatches these all together to the backed.

  • Is there a way to execute actions inmediately, without enqueuing? Or control the frequency of the dispatching job?
  • Or is it that we are something wrong, and $A.enqueueAction(...) is not the correct way to invoke an @AuraEnabled Apex method?

Thanks a lot!

  • Do you have any examples of the code where you are seeing this delay? The action queue should go back to the server pretty immediately unless there are other events kicking off. – pchittum Oct 16 '15 at 7:47
1

When you execute lightning framework actions outside the component lifecycle you have to wrap your code in a function and call it like this:

$A.getCallback(function () {//your code});

This problem usually happens when you are binding framework actions to UI events using a library like jQuery:

$(button).on('click', function () { $A.enqueueAction(myAction); // Force the queue to execute the actions immediately $A.getCallback(function () {}); });

Hope this can help. Thanks !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.