<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Continuation object &#8211; Jitendra Zaa</title>
	<atom:link href="https://www.jitendrazaa.com/blog/tag/continuation-object/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.jitendrazaa.com/blog</link>
	<description>AI, Salesforce, ServiceNow &#38; Enterprise Tech Guides</description>
	<lastBuildDate>Sat, 11 Jun 2022 15:01:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
<site xmlns="com-wordpress:feed-additions:1">87744916</site><atom:link rel="search" type="application/opensearchdescription+xml" title="Search Jitendra Zaa" href="https://www.jitendrazaa.com/blog/wp-json/opensearch/1.1/document" />	<item>
		<title>Design Continuation Server in Salesforce</title>
		<link>https://www.jitendrazaa.com/blog/salesforce/design-continuation-server-in-salesforce/</link>
					<comments>https://www.jitendrazaa.com/blog/salesforce/design-continuation-server-in-salesforce/#respond</comments>
		
		<dc:creator><![CDATA[Jitendra]]></dc:creator>
		<pubDate>Wed, 31 May 2017 15:48:09 +0000</pubDate>
				<category><![CDATA[Salesforce]]></category>
		<category><![CDATA[Asynchronous Apex]]></category>
		<category><![CDATA[Continuation]]></category>
		<category><![CDATA[Continuation object]]></category>
		<category><![CDATA[Continuation Server]]></category>
		<guid isPermaLink="false">http://www.jitendrazaa.com/blog/?p=6113</guid>

					<description><![CDATA[How to implement Continuation Server in Salesforce with the help of Action Function and Continuation Object]]></description>
										<content:encoded><![CDATA[<figure id="attachment_6115" aria-describedby="caption-attachment-6115" style="width: 1350px" class="wp-caption aligncenter"><img data-recalc-dims="1" fetchpriority="high" decoding="async" class="wp-image-6115 size-full" src="https://i0.wp.com/www.jitendrazaa.com/blog/wp-content/uploads/2017/05/Continuation-Server-using-Action-Function.gif?resize=1350%2C720&#038;ssl=1" alt="Continuation Server using ActionFunction in Salesforce" width="1350" height="720" /><figcaption id="caption-attachment-6115" class="wp-caption-text">Continuation Server using Action Function in Salesforce</figcaption></figure>
<p>Check the below video first if you are planning to use Continuation</p>
<p><iframe title="Continuation not needed anymore in Salesforce - Change My Mind" width="500" height="281" src="https://www.youtube.com/embed/ya2N9EX9dmg?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe></p>
<p style="text-align: justify;">If you are new to <strong>Continuation Object</strong> in Salesforce then would suggest to read <a href="https://www.jitendrazaa.com/blog/salesforce/continuation-object-in-apex-asynchronous-callouts-for-long-running-request-live-demo/">introduction post</a> first. In last post, we discussed how to <a href="https://www.jitendrazaa.com/blog/salesforce/limitless-chaining-of-continuation-object-in-salesforce/">implement limitless chaining of Continuation Object using JavaScript remoting</a>. In this post, we would try to achieve same, but instead of using JavaScript remoting, we would be using <strong>ActionFunction.</strong></p>
<p><strong>Why do we need chaining of Continuation Object</strong></p>
<ul>
<li style="text-align: justify;">From Apex, we can only chain 3 Continuation Object</li>
<li style="text-align: justify;">If we call API synchronously, chances are very high that it will run for more than 5 sec and contributing towards <strong>Concurrent Apex limit</strong></li>
<li style="text-align: justify;">Getting <strong>CPU timelimit </strong>error is also high</li>
<li style="text-align: justify;">Making synchronous call also means risking scalability of Salesforce instance</li>
<li style="text-align: justify;">You don&#8217;t want user to wait till call out completed, let them work and update user interface once response is received</li>
</ul>
<p style="text-align: justify;"><span id="more-6113"></span>Below code is assuming that Salesforce Lightning design system is uploaded as a static resource.</p>
<figure id="attachment_6111" aria-describedby="caption-attachment-6111" style="width: 840px" class="wp-caption aligncenter"><img data-recalc-dims="1" decoding="async" class="size-large wp-image-6111" src="https://i0.wp.com/www.jitendrazaa.com/blog/wp-content/uploads/2017/05/Salesforce-Continuation-Object-Error-1024x302.png?resize=840%2C248&#038;ssl=1" alt="What happens when we try to chain more than 3 Continuation Object call" width="840" height="248" srcset="https://i0.wp.com/www.jitendrazaa.com/blog/wp-content/uploads/2017/05/Salesforce-Continuation-Object-Error.png?resize=1024%2C302&amp;ssl=1 1024w, https://i0.wp.com/www.jitendrazaa.com/blog/wp-content/uploads/2017/05/Salesforce-Continuation-Object-Error.png?resize=300%2C88&amp;ssl=1 300w, https://i0.wp.com/www.jitendrazaa.com/blog/wp-content/uploads/2017/05/Salesforce-Continuation-Object-Error.png?resize=768%2C226&amp;ssl=1 768w, https://i0.wp.com/www.jitendrazaa.com/blog/wp-content/uploads/2017/05/Salesforce-Continuation-Object-Error.png?resize=1200%2C353&amp;ssl=1 1200w, https://i0.wp.com/www.jitendrazaa.com/blog/wp-content/uploads/2017/05/Salesforce-Continuation-Object-Error.png?w=1382&amp;ssl=1 1382w" sizes="(max-width: 840px) 100vw, 840px" /><figcaption id="caption-attachment-6111" class="wp-caption-text">What happens when we try to chain more than 3 Continuation Object call</figcaption></figure>
<figure id="attachment_6122" aria-describedby="caption-attachment-6122" style="width: 1342px" class="wp-caption aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" class="wp-image-6122 size-full" src="https://i0.wp.com/www.jitendrazaa.com/blog/wp-content/uploads/2017/05/Continuation-Demo.gif?resize=1342%2C720&#038;ssl=1" alt="Continuation Server in Salesforce - Demo" width="1342" height="720" /><figcaption id="caption-attachment-6122" class="wp-caption-text">Continuation Server in Salesforce &#8211; Demo</figcaption></figure>
<p><span style="text-decoration: underline;">ContinuationDemoController.class</span></p>
<pre><pre class="brush: java; title: ; notranslate">
/**
 * @Author		:		Jitendra Zaa
 * @Date		:		31 May 2017
 * @Desc		:		Demo of Continuation Server using Action Function
 *
 * */
public class ContinuationDemoController {  

    public String result {get;set;}
    private static final String CALLOUT_URL =
        'https://node-count.herokuapp.com/';
    public String apiCount {get;set;}
    public String callBackHandlerName {get;set;}
    String continuationState = '' ;
    public ContinuationDemoController(){
        result = '';
    } 

    public Object startRequest() {
      return constructCallout(callBackHandlerName,CALLOUT_URL, apiCount);
    } 

    public Object callout1Response() {
        HttpResponse response = Continuation.getResponse(continuationState);
        result = result + 'API'+ apiCount +' processing completed
 ' ;
        return null;
    }    

    private Continuation constructCallout(String callbackMethodName,String endpointURL, String apiCount){
        Continuation chainedContinuation = null;
        chainedContinuation = new Continuation(60);
        chainedContinuation.continuationMethod=callbackMethodName;
        HttpRequest req = new HttpRequest();
        req.setMethod('GET');
        req.setEndpoint(endpointURL+apiCount);
        continuationState = chainedContinuation.addHttpRequest(req);
        return chainedContinuation;
    }
}
</pre>
<p><span style="text-decoration: underline;">ContinuationDemo.page</span></p>
<pre><pre class="brush: xml; title: ; notranslate">
&amp;lt;apex:page controller="ContinuationDemoController" standardStylesheets="false" sidebar="false" showHeader="false"
 title="Continuation Server Demo"&amp;gt;
 &amp;lt;!-- &amp;lt;apex:slds /&amp;gt; --&amp;gt;
 &amp;lt;apex:stylesheet value="{!URLFOR($Resource.SLDS2_3_1, 'assets/styles/salesforce-lightning-design-system.min.css')}" /&amp;gt;
 &amp;lt;div class="slds slds-box"&amp;gt;
 &amp;lt;div class=" slds-m-top_xx-large slds-m-bottom_xx-large slds-m-left_xx-large slds-m-right_xx-large"&amp;gt;
 &amp;lt;apex:form &amp;gt;
 Total API calls to make : &amp;lt;input type="text" value="3" placeholder="Total API calls to make, Default 3" id="txtAPICallsToMake" /&amp;gt;
 &amp;lt;input value="Start Request" type="button" onclick="startRequest()"/&amp;gt; 

 &amp;lt;apex:actionFunction name="submitAPI" action="{!startRequest}" reRender="panel" oncomplete="apiComplete()"&amp;gt;
 &amp;lt;apex:param name="apiCount" assignTo="{!apiCount}" value="" /&amp;gt;
 &amp;lt;apex:param name="callBackHandlerName" assignTo="{!callBackHandlerName}" value="" /&amp;gt;
 &amp;lt;/apex:actionFunction&amp;gt; 

 &amp;lt;br /&amp;gt; &amp;lt;br /&amp;gt;

 &amp;lt;apex:outputPanel id="panel"&amp;gt;
 &amp;lt;apex:outputText value="{!result}" escape="false" /&amp;gt;
 &amp;lt;/apex:outputPanel&amp;gt;
 &amp;lt;/apex:form&amp;gt;
 &amp;lt;/div&amp;gt; 

 &amp;lt;div id="modalWindowMsg" style="height:640px;" class="hide"&amp;gt;
 &amp;lt;section role="dialog" tabindex="-1" aria-labelledby="modal-heading-01" aria-describedby="modal-content" class="slds-modal slds-fade-in-open"&amp;gt;
 &amp;lt;div class="slds-modal__container"&amp;gt;
 &amp;lt;header class="slds-modal__header"&amp;gt;
 &amp;lt;h2 id="modal-heading-01" class="slds-text-heading_medium slds-hyphenate"&amp;gt;API Callout status&amp;lt;/h2&amp;gt;
 &amp;lt;/header&amp;gt;
 &amp;lt;div class="slds-modal__content slds-p-around_medium" id="modal-content" &amp;gt;
 &amp;lt;p&amp;gt;
 &amp;lt;span id="modal-content-status"&amp;gt; Callout is in progress&amp;lt;/span&amp;gt;
 &amp;lt;/p&amp;gt;
 &amp;lt;p&amp;gt;
 &amp;lt;div class="demo-only" style="height:3rem;"&amp;gt;
 &amp;lt;div role="status" class="slds-spinner slds-spinner_medium"&amp;gt;
 &amp;lt;span class="slds-assistive-text"&amp;gt;Loading&amp;lt;/span&amp;gt;
 &amp;lt;div class="slds-spinner__dot-a"&amp;gt;&amp;lt;/div&amp;gt;
 &amp;lt;div class="slds-spinner__dot-b"&amp;gt;&amp;lt;/div&amp;gt;
 &amp;lt;/div&amp;gt;
 &amp;lt;/div&amp;gt;
 &amp;lt;/p&amp;gt;
 &amp;lt;/div&amp;gt;
 &amp;lt;footer class="slds-modal__footer"&amp;gt;
 &amp;lt;button class="slds-button slds-button_neutral" onclick="cancelModal()"&amp;gt;Cancel&amp;lt;/button&amp;gt;
 &amp;lt;/footer&amp;gt;
 &amp;lt;/div&amp;gt;
 &amp;lt;/section&amp;gt;
 &amp;lt;div id="modalWindowOverlay" class="slds-backdrop slds-backdrop_open"&amp;gt;&amp;lt;/div&amp;gt;
 &amp;lt;/div&amp;gt; 

 &amp;lt;/div&amp;gt;

 &amp;lt;style&amp;gt;
 .modal{
 visibility: visible !important;
 opacity: 1 !important;
 transition: opacity 0.4s linear;
 }
 .hide{
 display:none;
 }
 #modal-content{
 padding: 1rem;
 }
 &amp;lt;/style&amp;gt;

 &amp;lt;script&amp;gt;
 var calloutNum = 1 ;
 var totalCallout = 4;

 function openModal(){
 document.getElementById("modalWindowOverlay").classList.add('modal');
 document.getElementById("modalWindowMsg").classList.remove('hide');
 }
 function cancelModal(){
 document.getElementById("modalWindowOverlay").classList.remove('modal');
 document.getElementById("modalWindowMsg").classList.add('hide');
 calloutNum = totalCallout+1;
 }
 function startRequest(){
 openModal();
 var callnumbers = document.getElementById("txtAPICallsToMake").value;
 if(callnumbers){
 totalCallout = callnumbers;
 }

 document.getElementById("modal-content-status").innerHTML = 'Callout request started for API - '+calloutNum;
 submitAPI(calloutNum,'callout1Response');
 }

 function apiComplete(){
 if(calloutNum &amp;lt; totalCallout){
 calloutNum++;
 document.getElementById("modal-content-status").innerHTML = 'Callout request started for API - '+calloutNum;
 submitAPI(calloutNum,'callout1Response');
 }else{
 document.getElementById("modalWindowOverlay").classList.remove('modal');
 document.getElementById("modalWindowMsg").classList.add('hide');
 }
 }
 &amp;lt;/script&amp;gt;
&amp;lt;/apex:page&amp;gt;
</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://www.jitendrazaa.com/blog/salesforce/design-continuation-server-in-salesforce/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">6113</post-id>	</item>
		<item>
		<title>Limitless Chaining of Continuation object in Salesforce</title>
		<link>https://www.jitendrazaa.com/blog/salesforce/limitless-chaining-of-continuation-object-in-salesforce/</link>
					<comments>https://www.jitendrazaa.com/blog/salesforce/limitless-chaining-of-continuation-object-in-salesforce/#comments</comments>
		
		<dc:creator><![CDATA[Jitendra]]></dc:creator>
		<pubDate>Wed, 31 May 2017 03:30:40 +0000</pubDate>
				<category><![CDATA[Salesforce]]></category>
		<category><![CDATA[Asynchronous Apex]]></category>
		<category><![CDATA[Continuation]]></category>
		<category><![CDATA[Continuation object]]></category>
		<category><![CDATA[Continuation Server]]></category>
		<category><![CDATA[JavaScript Remoting]]></category>
		<guid isPermaLink="false">http://www.jitendrazaa.com/blog/?p=6101</guid>

					<description><![CDATA[How to create a Continuation Server in Salesforce with the help of JavaScript remoting and Continuation Object]]></description>
										<content:encoded><![CDATA[<figure id="attachment_6102" aria-describedby="caption-attachment-6102" style="width: 1410px" class="wp-caption aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" class="size-full wp-image-6102" src="https://i0.wp.com/www.jitendrazaa.com/blog/wp-content/uploads/2017/05/Continuation-Object-GIF.gif?resize=1410%2C720&#038;ssl=1" alt="Chaining of Continuation Object in Salesforce" width="1410" height="720" /><figcaption id="caption-attachment-6102" class="wp-caption-text">Chaining of Continuation Object in Salesforce</figcaption></figure>
<p>Check the below video first if you are planning to use Continuation</p>
<p><iframe loading="lazy" title="Continuation not needed anymore in Salesforce - Change My Mind" width="500" height="281" src="https://www.youtube.com/embed/ya2N9EX9dmg?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe></p>
<p style="text-align: justify;">Around two years back, I posted an article on <a href="https://www.jitendrazaa.com/blog/salesforce/continuation-object-in-apex-asynchronous-callouts-for-long-running-request-live-demo/">Continuation Object</a> in Salesforce. As we know because of governor limits like <strong>concurrent Apex limit </strong>or <strong>CPU time limit </strong>errors, its always recommended to perform long running Apex process asynchronously. Processes specially like calling external API.</p>
<p style="text-align: justify;">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&#8217;s from Javascript (like using JavaScript remoting) then still we are using synchronous Apex which would be trade off for scalability.</p>
<figure id="attachment_6111" aria-describedby="caption-attachment-6111" style="width: 840px" class="wp-caption aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" class="size-large wp-image-6111" src="https://i0.wp.com/www.jitendrazaa.com/blog/wp-content/uploads/2017/05/Salesforce-Continuation-Object-Error-1024x302.png?resize=840%2C248&#038;ssl=1" alt="What happens when we try to chain more than 3 Continuation Object call" width="840" height="248" srcset="https://i0.wp.com/www.jitendrazaa.com/blog/wp-content/uploads/2017/05/Salesforce-Continuation-Object-Error.png?resize=1024%2C302&amp;ssl=1 1024w, https://i0.wp.com/www.jitendrazaa.com/blog/wp-content/uploads/2017/05/Salesforce-Continuation-Object-Error.png?resize=300%2C88&amp;ssl=1 300w, https://i0.wp.com/www.jitendrazaa.com/blog/wp-content/uploads/2017/05/Salesforce-Continuation-Object-Error.png?resize=768%2C226&amp;ssl=1 768w, https://i0.wp.com/www.jitendrazaa.com/blog/wp-content/uploads/2017/05/Salesforce-Continuation-Object-Error.png?resize=1200%2C353&amp;ssl=1 1200w, https://i0.wp.com/www.jitendrazaa.com/blog/wp-content/uploads/2017/05/Salesforce-Continuation-Object-Error.png?w=1382&amp;ssl=1 1382w" sizes="auto, (max-width: 840px) 100vw, 840px" /><figcaption id="caption-attachment-6111" class="wp-caption-text">What happens when we try to chain more than 3 Continuation Object in Salesforce</figcaption></figure>
<p>In Short, below are challenges in front of us</p>
<ul>
<li style="text-align: justify;">We need to call 10+ API from Visualforce</li>
<li style="text-align: justify;">Cannot use chaining of <strong>Continuation Object</strong> as current chaining limit is 3</li>
<li style="text-align: justify;">Cannot invoke each API from <strong>JavaScript remoting</strong> because it will be considered as Synchronous Apex</li>
</ul>
<p><span id="more-6101"></span></p>
<p style="text-align: justify;">Lots of talk, now get into action. We would discuss how to create <strong>a Continuation Server in Salesforce with the help of Continuation Object and JavaScript remoting. </strong>In this approach, we would be able to call unlimited APIs asynchronously from Salesforce.</p>
<p><iframe loading="lazy" title="Continuation Server in Salesforce using Continuation Object and JavaScript Remoting" width="500" height="281" src="https://www.youtube.com/embed/U2-UwucMBfc?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe></p>
<p><span style="text-decoration: underline;">continuationDemoJSRemoting.vfp</span></p>
<pre><pre class="brush: xml; title: ; notranslate">
 &amp;lt;apex:page controller="ContinuationDemoJSRemoting" standardStylesheets="false" sidebar="false" showHeader="false" title="Continuation Server Demo"&amp;gt;
 &amp;lt;!-- &amp;lt;apex:slds /&amp;gt; Images (loading image) are not imported using this tag --&amp;gt;
 &amp;lt;apex:stylesheet value="{!URLFOR($Resource.SLDS2_3_1, 'assets/styles/salesforce-lightning-design-system.min.css')}" /&amp;gt; 

 &amp;lt;div aria-hidden="true" style="width:100%;height:100%"&amp;gt;
 &amp;lt;div class="slds slds-box slds-scope"&amp;gt;
 &amp;lt;div class=" slds-m-top_xx-large slds-m-bottom_small"&amp;gt;
 Total API calls to make : &amp;lt;input type="text" value="3" placeholder="Total API calls to make, Default 3" id="txtAPICallsToMake" /&amp;gt;
 &amp;lt;input value="Start Request" type="button" onclick="startRequest()"/&amp;gt;
 &amp;lt;/div&amp;gt;
 &amp;lt;br /&amp;gt; &amp;lt;br /&amp;gt;

 &amp;lt;div&amp;gt;
 Note : With increase in each API count, Response time would also be increased. &amp;lt;br /&amp;gt;
 &amp;lt;b&amp;gt;Responses :&amp;lt;/b&amp;gt; &amp;lt;span id="resultContainer"&amp;gt;&amp;lt;/span&amp;gt;
 &amp;lt;/div&amp;gt; 

 &amp;lt;div id="modalWindowMsg" style="height:640px;" class="hide"&amp;gt;
 &amp;lt;section role="dialog" tabindex="-1" aria-labelledby="modal-heading-01" aria-describedby="modal-content" class="slds-modal slds-fade-in-open"&amp;gt;
 &amp;lt;div class="slds-modal__container"&amp;gt;
 &amp;lt;header class="slds-modal__header"&amp;gt;
 &amp;lt;h2 id="modal-heading-01" class="slds-text-heading_medium slds-hyphenate"&amp;gt;API Callout status&amp;lt;/h2&amp;gt;
 &amp;lt;/header&amp;gt;
 &amp;lt;div class="slds-modal__content slds-p-around_medium" id="modal-content" &amp;gt;
 &amp;lt;p&amp;gt;
 &amp;lt;span id="modal-content-status"&amp;gt;&amp;lt;/span&amp;gt;
 &amp;lt;/p&amp;gt;
 &amp;lt;p&amp;gt;
 &amp;lt;div class="demo-only" style="height:3rem;"&amp;gt;
 &amp;lt;div role="status" class="slds-spinner slds-spinner_medium"&amp;gt;
 &amp;lt;span class="slds-assistive-text"&amp;gt;Loading&amp;lt;/span&amp;gt;
 &amp;lt;div class="slds-spinner__dot-a"&amp;gt;&amp;lt;/div&amp;gt;
 &amp;lt;div class="slds-spinner__dot-b"&amp;gt;&amp;lt;/div&amp;gt;
 &amp;lt;/div&amp;gt;
 &amp;lt;/div&amp;gt;
 &amp;lt;/p&amp;gt;
 &amp;lt;/div&amp;gt;
 &amp;lt;footer class="slds-modal__footer"&amp;gt;
 &amp;lt;button class="slds-button slds-button_neutral" onclick="cancelModal()"&amp;gt;Cancel&amp;lt;/button&amp;gt;
 &amp;lt;/footer&amp;gt;
 &amp;lt;/div&amp;gt;
 &amp;lt;/section&amp;gt;
 &amp;lt;div id="modalWindowOverlay" class="slds-backdrop slds-backdrop_open"&amp;gt;&amp;lt;/div&amp;gt;
 &amp;lt;/div&amp;gt;
 &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
 &amp;lt;style&amp;gt;
 .modal{
 visibility: visible !important;
 opacity: 1 !important;
 transition: opacity 0.4s linear;
 }
 .hide{
 display:none;
 }
 #modal-content{
 padding: 1rem;
 }
 &amp;lt;/style&amp;gt;
 &amp;lt;script type="text/javascript"&amp;gt;
 Visualforce.remoting.timeout = 120000;
 var apiNumber = 1;
 var totalAPICallsToMake = 3;
 var resultContainer = document.getElementById("resultContainer") ;
 var modalcontentstatus = document.getElementById("modal-content-status") ;
 var startTime,endTime,elapsedSecond; 

 function startRequest(){
 var callnumbers = document.getElementById("txtAPICallsToMake").value;
 if(callnumbers){
 totalAPICallsToMake = callnumbers;
 }
 document.getElementById("modalWindowOverlay").classList.add('modal');
 document.getElementById("modalWindowMsg").classList.remove('hide');
 submitCalls(apiNumber);
 }

 function submitCalls(count){
 modalcontentstatus.innerHTML='Callback initiated for API number - '+count;
 startTime = new Date().getTime();
 Visualforce.remoting.Manager.invokeAction(
 '{!$RemoteAction.ContinuationDemoJSRemoting.callService}',
 count,
 handleResult
 );
 }

 function handleResult(result, event){
 endTime = new Date().getTime();
 elapsedSecond = (endTime - startTime) / 1000;
 modalcontentstatus.innerHTML='Callback completed';
 if (event.status) {
 resultContainer.innerHTML=resultContainer.innerHTML+'&amp;lt;br /&amp;gt; Time Taken for API '+ apiNumber +' : '+elapsedSecond+' sec , Response : '+result;
 }

 if(apiNumber &amp;lt; totalAPICallsToMake){
 apiNumber++;
 submitCalls(apiNumber);
 }else{
 cancelModal();
 }
 } 

 function cancelModal(){
 document.getElementById("modalWindowOverlay").classList.remove('modal');
 document.getElementById("modalWindowMsg").classList.add('hide');
 }
 &amp;lt;/script&amp;gt;
&amp;lt;/apex:page&amp;gt;
</pre>
<p><span style="text-decoration: underline;">ContinuationDemoJSRemoting.class</span></p>
<pre><pre class="brush: java; title: ; notranslate">
/**
 * @Author		:		Jitendra Zaa
 * @Date		:		30 May 2017
 * @Desc		:		Demo of Continuation Server using Javascript remoting
 *
 * */
public class ContinuationDemoJSRemoting {

    private static final String CALLOUT_URL = 'https://node-count.herokuapp.com/';
    private static Map&amp;lt;Integer,String&amp;gt; errors = null;

    private static void initializeErrorcodes(){
        if(errors == null){
            errors = new Map&amp;lt;Integer,String&amp;gt;();
            errors.put(2000,'The timeout was reached, and the server did not get a chance to respond.');
            errors.put(2001,'There was a connection failure.');
            errors.put(2002,'Exceptions occurred.');
            errors.put(2003,'The response hasn’t arrived (which also means that the Apex asynchronous callout framework hasn’t resumed).');
            errors.put(2004,'The response size is too large (greater than 1 MB).');
        }
    }

    @RemoteAction
    public static Object callService(Integer count){
        // Return it to the system for processing
        return constructCallout('callback1Respone',count);
    }

    public static Object callback1Respone(Object state) {
        HttpResponse response = Continuation.getResponse((String)state);
        Integer statusCode = response.getStatusCode();
        if (statusCode &amp;gt;= 2000) {
            initializeErrorcodes();
            return 'Continuation error: ' + errors.get(statusCode);
        }
        return response.getBody();
    }

    private static Object constructCallout(String callbackMethodName,Integer count){
        Continuation chainedContinuation = null;
        chainedContinuation = new Continuation(60);
        chainedContinuation.continuationMethod=callbackMethodName;
        HttpRequest req = new HttpRequest();
        req.setMethod('GET');
        req.setEndpoint(CALLOUT_URL+count);
        chainedContinuation.state = chainedContinuation.addHttpRequest(req);
        return chainedContinuation;
    } 

}
</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://www.jitendrazaa.com/blog/salesforce/limitless-chaining-of-continuation-object-in-salesforce/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">6101</post-id>	</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 
Minified using Disk

Served from: www.jitendrazaa.com @ 2026-06-12 23:08:48 by W3 Total Cache
-->