Apex Callouts – Chaining from JavaScript Controller Using Async/Await or Promise

apexcalloutlightning-web-components

I need to make 5 callouts serially. I have written 5 different apex classes. I want to chain these callouts from JavaScript controller using Async/Await or Promises. Had anyone worked on such scenario? Any problems or blockers? Each call is taking few seconds – so no timeout issue. I am logging each callout results, so I might get uncommitted work pending exception. Please suggest

Best Answer

There's no concern there. As long as each callout occurs before the DML in each Apex transaction, you'll be fine. For example, you can write your logic like this:

let result1 = await apexMethod1();
let result2 = await apexMethod2();
let result3 = await apexMethod3();
let result4 = await apexMethod4();
let result5 = await apexMethod5();

Each result will have been obtained from a separate transaction that each had their own separate governor limits.