function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Florian Dardelet 7Florian Dardelet 7 

How to properly orchestrate apex calls from LWC

Hello,

I have a process to harvest a price list that requires the orchestration of multiple Apex methods, including a callout to an external API and interpretation of its response. If you coordinate the series of operations through a back-end Apex for a single price request, this routinely exceeds the governor limit. In addition, each element in the orchestration has a dependency on its predecessors, meaning that I must call them synchronously. 

I've created a LWC that takes care of that orchestration from the browser. The benefit is that I can create multiple price requests and fire them one after the other, however I run into 2 issues: 

1. I often get a "communication error - no response from server" when I send too many requests in parallel, which I cannot explain at this point. I suspect it's driven by the limit of 100 simultaneous Apex operations active on the org, but I'm not sure.

2. I cannot find an efficient way to send a batch of pricing requests which would all get coordinated from the browser. 

Is there a best-practice in LWC for calling a series of apex sequentially? Or is there a best way to do it? 

In practice, this looks like this: 

1. User creates or uploads a series of price requests (up to 200 individual request). 

2. LWC lists all pending requests with a "Harvest" button which will fetch the price details to the supplier's API, then interprets and cascade the price to all records that require updating. We use formulas where possible, but a lot of records still need to be manipulated. 

3. Once the user clicks on harvest, this particular request gets orchestrated by a JS function until it's completed. At the end of the orchestration, the JS refreshes the list of price queries and the active one is removed from the list by the controller class. 

4. If the user harvests too many requests at the same time, it will trigger a server communication error.

This is preventing me from creating a "Harvest All" method that will go through the list in order. 

 

Thanks for any help