4

I keep getting an error that the @RemoteAction method I'm calling doesn't exist.
Here is the error text:

No remoted actions found to resolve '$RemoteAction.FileRemoting.rename_file'

It does exist, but it's not in my controller class.

Is it possible to call a remote method from a different class, and if so, what am I missing?

EDIT I should have mentioned this: I am using a custom controller, so doing it as an extension gives me an error that looks like this:

Unknown constructor 'FileRemoting.FileRemoting(GlobalSearch_Custom controller)'

I'm not sure if there's an implicit base class, or if I'd have to create, and then inherit from some generic/empty base class.

1 Answer 1

5

Try adding the other class as an extension in your opening <apex:page> tag. You can do this for multiple classes by separating them with commas.

<apex:page controller="SomeApex_Controller"
    extensions="FileRemoting,AnotherHelperClass">

Edit:

To resolve the custom controller error you're getting, you can either add a constructor to the FileRemoting class for your particular class that wants to use the helper remoting methods, or derive the constructor from a base class that your initial controller then extends.

Option 1:

public class FileRemoting {
    public FileRemoting(GlobalSearch_Custom controller) {
        // do something, although you don't have to do anything here
    }
    // you will need to add separate constructors for each page
    // that you want to leverage this class (unless they use the same controller)
}

Option 2:

public abstract class CustomControllerBase {
    // you'd probably just want to leave this blank rather than force extending classes to implement something
}

public class GlobalSearch_Custom extends CustomControllerBase {
    // custom controller class body
    // note that any other controller that wants to use FileRemoting methods will
    // also need to extend the CustomControllerBase class
}

public class FileRemoting {
    public FileRemoting(CustomControllerBase controller) {
        // do something, although you don't have to do anything here
    }
}

Either of these options should allow you to reference the FileRemoting class as an extension in your VF page.

5
  • Thanks for helping! I tried the extension, but failed to mention in my original post that it's not a standard controller - It's a custom controller, so I'm getting really "unique" errors. Commented Nov 5, 2015 at 19:07
  • @HungryBeagle please see my updated response.
    – JCD
    Commented Nov 5, 2015 at 19:36
  • That is the method I ended up using - Thanks for your help! Commented Nov 5, 2015 at 19:41
  • I just stumbled upon this. Do you have any information about why it is the way it is? I couldn't find anything about this in the documentation.
    – Semmel
    Commented Aug 29, 2018 at 10:02
  • @Semmel I reckon it's a security feature to prevent a page from accessing exposed methods elsewhere in your Apex codebase that aren't intended for use on said page. For example, we have publicly-exposed VF pages that utilize JS remoting; if a malicious SF/JS guru happened to check out the source, they could get some bright ideas about calling other methods in our org. Although that would require some knowledge about our class structure, naming conventions, etc. Extremely unlikely, yes, but within the realm of possibility.
    – JCD
    Commented Aug 29, 2018 at 13:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .