Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.

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. With interface parameters and return types, a package provider can package a remote method and associated interface, which subscriber orgs can call from Visualforce pages. Subscriber orgs pass in their own class that implements the packaged interface.

If a @RemoteAction method is in a managed package and used by Visualforce Remoting, it must have global visibility if user profile or permission set access is used.

Note

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 RemoteController:
1Visualforce.remoting.Manager.invokeAction(
2    '{!$RemoteAction.RemoteController.setMessage}',
3    {'apexType':'thenamespace.RemoteController.MyClass', 'myString':'Lumos!'}, 
4    handleResult
5);
If the class definition is within your organization, you can simplify the remoting call and use the default c namespace:
1RemoteController.setMessage(
2    {'apexType':'c.RemoteController.MyClass', 'myString':'Lumos!'}, 
3    handleResult
4);