Did $A.enqueueAction(action) grouped your actions?

Manjot Singh
Salesforce-Lightning
2 min readFeb 21, 2018

I have written detailed description of issues which can occur due to enqueue action in my blog at techgita.com

If you want to know how to run each and every action seprately then you can use enqueue component i have written.

Lets say we are building a lightning component. Its structure is

On init of component 1 and component 2 , i am making an api call to query data. Comp1 is querying 26000 records and comp2 is also querying 26000 records. Now above api calls might work sometime. But if framework groups your api calls and then your SOQL governer limit will be reached.

Now 1 solution will be firing application event from Comp1 and tell Comp2 that i have recived my Response you can make api call.

Another Solution is to use enqueueAction Component. It is a open source Component i am working on.

This is the how we normally call the actions in js.

To use enqueue component we have to make few changes in Comp5. We have to wrap child components from where action is called in enqueueAction Component.

After that we have to make changes in how api’s are called from of Comp1 and Comp2. In .cmp file of Comp1 and Comp2 we have to register 2 events.

Now instead of enqueuing the action i am firing an add event from child component. You can see that i have used setTimout(). setTimout() can be used if you are firing event on init. Because if you are firing event from child component even before parent in initialized then parent cannot handle this event. You can replace

setTimeout($A.getCallback(() => component.getEvent(‘add’).setParams({actionObject:action}).fire()));

with

component.getEvent(‘add’).setParams({actionObject:action}).fire());

if you are not firing add event on init.

After you recieved your response you will have to fire remove event to remove action from queue.

I will suggest to you enqeueAction only if your api might hit governer limits if grouped together.

Here is a link to git hub repo for enqueueAction Component

If you have any suggestion on how to improve performance of enqueueAction Component, you can share here or on git.

--

--