Managing the order of execution and asynchronous processes

We have a Skuid page- Page1 - with a Save button, which saves a parent object record and related child records created on the page. There are a sequence of actions associated to this button.

Approach 1

  1. Saves parent records
  2. Runs Snippet1 on child records, updates certain fields on the rows in the model
  3. Save child records
  4. Redirect to the parent detail page
Approach 2 
  • Step 1 
  • Step 2A save() method on the end of Snippet1 saves the child records here. (Step 3)
  • Step 4
Approach 3
  • Step 1 
  • Step 2, only in this case both Step 3 and Step 4 were appended as JS in the Snippet1.
In Approach 2, sometimes on landing the detail page in Step 4, the child records are not yet created. On refreshing the page, they are listed in the related list. Step 4 runs before the Snippet1 has completed its run. Approach 3 was adopted as an a solution to this.

Now, Approach 1 was used in an unrelated page - Page2 , but never encountered this problem. But then again, the latter page has relatively lower complexity in calculations in snippets and lesser records to save.

Q1. What is the behaviour of execution (sync/async) when Approach 2 or 3 is used, and how is it different from Approach 1?
Q2. The problem was not encountered in the Page2, what could be the reason for this - complexity? data volume? Is there a “potential danger” in the Page2 in that case?

The key issue here is that the action framework steps are not waiting for completion of asynchronous processes before going to the next Step.  Step 2 does not wait for Step 1 to be completed before it starts.  This is why approach 2 is causing problems.  The save method is a-synchronous.  It looks like approach 1 only has synchronous processes in its snippet.  Generally any actions just occuring in the client will by synchronous, while any actions that go to the Salesforce servers are going to be a-synchronous. 

If the calculations in your snippet include any server processing they will need to use the JQuery deferred / promise approach to make them synchronous.  Here is another forum post that discusses the concept:

Hope that helps. 

Thank you Rob. That explains it. :slight_smile: