I have a parent class that provides a set of remote action methods that are common to my other controllers:
global virtual with sharing class MyBaseClass {
@RemoteAction
global static void remoteMethodA () {
// stuff
}
@RemoteAction
global static void remoteMethodB () {
// stuff
}
}
and child classes that inherit the base class. One of the child classes needs a different implementation of one of the remote action methods:
global with sharing class MyChildClass extends MyBaseClass {
@RemoteAction
global static void remoteMethodA () {
// this is different from MyBaseClass
}
}
Per Salesforce's Remote Methods and Inheritance, static remote action methods are "inherited"* by child classes. The problem is that Salesforce doesn't know not to inherit remoteMethodA
in MyChildClass
, and the Visualforce remote object throws an error on page load:
Visualforce Remoting: Unable to create method 'remoteMethodA': already exists on object 'MyChildClass'
It seems to default to using the child class remote action method, as the page works properly, but I would like to clear up the error if I can. Is there a way to tell Visualforce that the child class method overrides the parent class method?
* Static methods are not inherited in any OOP sense – Visualforce walks up the chain of inheritance to build a list of available remote actions.
Best Answer
I guess you have two options:
remoteMethodC
I'd recommend the second approach for a few reasons: