Created
April 26, 2016 09:58
-
-
Save swapnilshrikhande/2814cc964d55528d891eb2f862a612a6 to your computer and use it in GitHub Desktop.
Deferred to wait for two remote actions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DeferredTest { | |
@RemoteAction | |
public static String remoteActionOne(){ | |
return 'one'; | |
} | |
@RemoteAction | |
public static String remoteActionTwo(){ | |
return 'two'; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<apex:page controller="DeferredTest"> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script> | |
<script> | |
$(document).ready(function(){ | |
var deferredOne = $.Deferred(); | |
var deferredTwo = $.Deferred(); | |
$.when(deferredOne,deferredTwo).then(function(){ | |
console.log('Both 1 and 2 remoting are done'); | |
}); | |
funcCallRemoteOne(deferredOne); | |
funcCallRemoteTwo(deferredTwo); | |
}); | |
var funcCallRemoteOne = function(deferred){ | |
Visualforce.remoting.Manager.invokeAction( | |
'{!$RemoteAction.DeferredTest.remoteActionOne}', | |
function(result,event){ | |
console.log(result); | |
deferred.resolve(); | |
} | |
); | |
}; | |
var funcCallRemoteTwo = function(deferred){ | |
Visualforce.remoting.Manager.invokeAction( | |
'{!$RemoteAction.DeferredTest.remoteActionTwo}', | |
function(result,event){ | |
console.log(result); | |
deferred.resolve(); | |
} | |
); | |
} | |
</script> | |
</apex:page> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment