Remote action methods in page cannot complete/find usage methods in page controllers superclass

Issue #1784 resolved
Ben Heap created an issue

In our project, we have pages that within a section of javascript make RemoteAction calls to a method that is available on the page controllers superclass. This enables us to create ‘base’ controllers for code reuse. However these methods are never linked/findable/completable despite the code being deployable and working fine. This leads to the danger of refactoring of base methods breaking our pages.

For example

Given the following

public virtual with sharing class Base_Controller {

    @RemoteAction
    public static String getMeSomethingUsingBase() {
    }
}
public with sharing class New_Page_Controller extends Base_Controller {

    @RemoteAction
    public static String getMeSomethingUsingNewPage() {
    }
}
<apex:page controller="New_Page_Controller">
    <html>
        <head>
            <script defer="defer">
                window.addEventListener("load", function() {

                    const findable = new some.packaged.js.method({
                        id: 'findable',
                        methods: {
                            get: {
                                method: '{!$RemoteAction.New_Page_Controller.getMeSomethingUsingNewPage}'
                            }
                        }
                    });

                    const not-findable = new some.packaged.js.method({
                        id: 'not-findable',
                        methods: {
                            get: {
                                method: '{!$RemoteAction.New_Page_Controller.getMeSomethingUsingBase}'
                            }
                        }
                    });
            </script>
        </head>

        <body></body>

    </html>
</apex:page>

In this example the first RemoteAction allows for completion whilst typing, is findable and refactorable as it references the page controllers own method.

The second RemoteAction does not complete, not is it findable or refactorable as it references the page controllers superclass method.

Comments (9)

  1. Scott Wells repo owner

    Updated example that reproduces the issue and shows the valid use of multiple controller classes:

    public with sharing virtual class BaseController {
        @RemoteAction
        public static String doSomethingInBase() {
            return null;
        }
    }
    
    public with sharing class DerivedController extends BaseController {
        public DerivedController(BaseController baseController) {}
    
        @RemoteAction
        public static String doSomethingInDerived() {
            return null;
        }
    }
    
    <apex:page id="Issue1784" controller="BaseController" extensions="DerivedController">
        <script lang="JavaScript">
            var result = '{!$RemoteAction.BaseController.doSomethingInBase}';
            var result2 = '{!$RemoteAction.DerivedController.doSomethingInBase}';
            var result3 = '{!$RemoteAction.DerivedController.doSomethingInDerived}';
        </script>
    </apex:page>
    
  2. Ben Heap reporter

    Hi Scott, thanks for the speedy response. In my example the @RemoteAction annotation was indeed missing (though this isn’t the case with the real issue and I’ve updated my example accordingly now).

    In your example you are referencing two different controllers in the same page (which I haven’t managed to push successfully to a scratch org). My understanding is that I can only reference one controller in the page.

    In my example I am referencing a method that is only present on the Base controller but via the DerivedController as I also want to use methods only present on the DerivedController in that page and this is the only way I’ve found to be able to push. This works fine in salesforce however accessing the base method via the derived controller doesn’t allow for completion etc…. using Illuminated Cloud

  3. Scott Wells repo owner

    Ah, okay. I see. Should be simple to gather remote action methods through the controller class hierarchy. I'll take a look at that for the next build. Thanks for helping to clarify the issue.

  4. Scott Wells repo owner

    Ben, I've updated my test case above such that it reproduces the issue (particularly the result2 declaration/assignment in the VF page's script) and also shows how you can use multiple controller classes via extensions.

  5. Log in to comment