JavaScript Remoting and Skuid

  • 1
  • Question
  • Updated 4 years ago
  • Answered
What is the proper pattern for using JavaScript Remoting i.e. @RemoteAction from a Skuid inline JavaScript resource?

Google-Bing led me to this article:
http://sowjitechblog.blogspot.com/2014/05/visualforce-make-remote-action-call.html

Any guidance or code snippets would be appreciated.

Regards,
Irvin
Photo of Irvin Waldman

Irvin Waldman, Champion

  • 9,006 Points 5k badge 2x thumb

Posted 4 years ago

  • 1
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
The approach documented under "From a Static Resource" in that article is the proper way to go.

For instance, if your VF Page's Apex Controller is called "TurboThrusters" and it defines a RemoteAction named "Engage" that expects a single number argument, then your JavaScript would call it like this:

var thursterPower = 50;

TurboThrusters.Engage(thrusterPower,function(result,event){
   if (event.status) {
       console.log('Got response back from server okay');
      console.log(result);
   }
});
Photo of Irvin Waldman

Irvin Waldman, Champion

  • 9,006 Points 5k badge 2x thumb
Alright, that's the way I will go.  Thanks!
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
Also keep in mind that if your code is in a managed package, then you will need to use the Namespace Prefix of that managed package. For instance if your namespace is "galactic", then you would need to do this:

galactic.TurboThrusters.Engage(thrusterPower,function(result,event){
   if (event.status) {
       console.log('Got response back from server okay');
      console.log(result);
   }
});
Photo of Irvin Waldman

Irvin Waldman, Champion

  • 9,006 Points 5k badge 2x thumb
Thanks.  You probably just saved me a few minutes of wailing-n-gnashing.
Photo of Irvin Waldman

Irvin Waldman, Champion

  • 9,006 Points 5k badge 2x thumb
Worked out great.  Thanks again.