Newer Version Available
Remote Methods and Inheritance
You can call remote actions on your Apex controller that are
inherited methods. When a @RemoteAction method is
looked up or called, Visualforce
inspects the page controller’s inheritance hierarchy and finds @RemoteAction methods in the controller’s ancestor
classes.
Here’s an example demonstrating this capability. The following Apex classes form a three-tier
inheritance
hierarchy:
1global with sharing class ChildRemoteController
2 extends ParentRemoteController { }
3global virtual with sharing class ParentRemoteController
4 extends GrandparentRemoteController { }
5
6global virtual with sharing class GrandparentRemoteController {
7 @RemoteAction
8 global static String sayHello(String helloTo) {
9 return 'Hello ' + helloTo + ' from the Grandparent.';
10 }
11}This Visualforce page simply calls the
sayHello remote
action.
The
remote method doesn’t exist in the ChildRemoteController
class. Instead, it’s inherited from GrandparentRemoteController.
1swfobject.registerObject("clippy.codeblock-1", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17<apex:page controller="ChildRemoteController" >
18 <script type="text/javascript">
19 function sayHello(helloTo) {
20 ChildRemoteController.sayHello(helloTo, function(result, event){
21 if(event.status) {
22 document.getElementById("result").innerHTML = result;
23 }
24 });
25 }
26 </script>
27
28 <button onclick="sayHello('Jude');">Say Hello</button><br/>
29 <div id="result">[Results]</div>
30
31</apex:page>