1

I just read the best practices article for the Lightning and I am wondering is that possible to have more than one enqueueaction in client controller js? Please suggest. There is some hint given in best practices (highlighted) that composite request is possible. Please provide some code snippet of how it can be achieved. Thanks.

Lightning Components Performance Best Practices

enter image description here

  • Please include any citations as text, not images. – Adrian Larson Mar 24 '18 at 20:36
  • Thanks @AdrianLarson. I would make a note of your suggestion. – Bforce Mar 25 '18 at 3:55
5

There's two basic mechanisms for composite requests. For completely unrelated requests, simply call $A.enqueueAction for each action you'd like to queue; they'll get handled a few at a time (as explained in Lightning's "Boxcarred Action" and Its Behavior).

$A.enqueueAction(action1);
$A.enqueueAction(action2);

When you have a scenario where you call the server, get data back, then call the server again, etc, consider if it's possible to write a wrapper object and return all the data at once (hint: you usually can). The fewer times you need to hit the server, the better off you'll be.

public class ComponentInitResponse {
  @AuraEnabled public PicklistOptions[] valuesForStage, valuesForStatus;
  @AuraEnabled public Lead record;
}

In this example, instead of just describing picklist values, then calling a separate response to get the Lead record, we combined them into a single composite, which is slightly more efficient.

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.