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:
public class RemoteController {
public interface MyInterface { String getMyString(); }
public class MyClass implements MyInterface {
private String myString;
public String getMyString() { return myString; }
public void setMyString(String s) { myString = s; }
}
@RemoteAction
public static MyInterface setMessage(MyInterface i) {
MyClass myC = new MyClass();
myC.setMyString('MyClassified says "' + i.getMyString() + '".');
return myC;
}
}
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:
Visualforce.remoting.Manager.invokeAction(
'{!$RemoteAction.RemoteController.setMessage}',
{'apexType':'thenamespace.RemoteController.MyClass', 'myString':'Lumos!'},
handleResult
);
If the class definition is within your organization, you can
simplify the remoting call, and also use the default
c
namespace:
RemoteController.setMessage(
{'apexType':'c.RemoteController.MyClass', 'myString':'Lumos!'},
handleResult
);