Limitless Chaining of Continuation object in Salesforce

Chaining of Continuation Object in Salesforce
Chaining of Continuation Object in Salesforce

Check the below video first if you are planning to use Continuation

Around two years back, I posted an article on Continuation Object in Salesforce. As we know because of governor limits like concurrent Apex limit or CPU time limit errors, its always recommended to perform long running Apex process asynchronously. Processes specially like calling external API.

We can come up with multiple designs if number of APIs are less. However, you would risk scalability of Salesforce if number of APIs to be called is 10+. We cannot use chaining of continuation object directly as currently its limited to 3. If we call these API’s from Javascript (like using JavaScript remoting) then still we are using synchronous Apex which would be trade off for scalability.

What happens when we try to chain more than 3 Continuation Object call
What happens when we try to chain more than 3 Continuation Object in Salesforce

In Short, below are challenges in front of us

  • We need to call 10+ API from Visualforce
  • Cannot use chaining of Continuation Object as current chaining limit is 3
  • Cannot invoke each API from JavaScript remoting because it will be considered as Synchronous Apex

Visualforce Remote Objects

One of the exciting feature of Spring14 release is introduction of “Visualforce Remote Objects”. You can say its actually replacement of JavaScript Remoting.

Why do we need “Visualforce Remote Objects” when we already have “JavaScript Remoting” ?

Well, here are few advantages of “Visualforce Remote Objects” :

  1. No need to write Controllers, Everything can be done in Visualforce only.
  2. As @RemoteAction annotated methods needs to be static so you had to take special precaution as it didn’t supported Viewstate. This hurdle is completely removed now.
  3. No need to write Test Class now, as no Controller is involved.