Newer Version Available
Declaring a Remote Method with Interface Parameters
You can declare @RemoteAction methods with
interface parameters and return types, instead of being restricted to concrete classes. This, for
example, allows a package provider to package a remote method and associated interface, which
subscriber organizations can call from Visualforce pages, passing in their own class
that implements the packaged interface.
Here’s a brief
example:
1public class RemoteController {
2 public interface MyInterface { String getMyString(); }
3 public class MyClass implements MyInterface {
4 private String myString;
5 public String getMyString() { return myString; }
6 public void setMyString(String s) { myString = s; }
7 }
8
9 @RemoteAction
10 public static MyInterface setMessage(MyInterface i) {
11 MyClass myC = new MyClass();
12 myC.setMyString('MyClassified says "' + i.getMyString() + '".');
13 return myC;
14 }
15}
Objects sent from a JavaScript remoting call to a @RemoteAction that declares interface parameters must include an
apexType value, which must be a fully-qualified path to the
concrete class, that is, namespace[.BaseClass][.ContainingClass].ConcreteClass.
For example, to make a JavaScript remoting call to the above
controller:
1Visualforce.remoting.Manager.invokeAction(
2 '{!$RemoteAction.RemoteController.setMessage}',
3 {'apexType':'thenamespace.RemoteController.MyClass', 'myString':'Lumos!'},
4 handleResult
5);