1

Im trying to call a controller from my external js file, and im getting the title error, have you guys seen anything like this?

Page:

<apex:page controller="TestController" showHeader="false" sidebar="false">
<html lang="en">
    <head>
        <meta charset="utf-8"/>
        <script>
            window.configSettings = {
                remoteActions: {
                    helloWorld: '{!$RemoteAction.TestController.helloWorld}'
                }
           }
        </script>
        <apex:includeScript value="{!$Resource.testJs}" loadOnReady="true"/>
    </head>
</html>

Controller:

public class TestController {
@ReadOnly
@RemoteAction
public static String helloWorld(){
    return 'hello world';
}
}

Javascript:

(function (window){
Visualforce.remoting.Manager.invokeAction(
    window.configSettings.helloWorld,
    function(result, event){
        console.log(result);
    },
    {buffer: true, escape: true}
);
})(window);
2

Well my dudes, it turns out im really stupid haha, i was trying to access the function without passing its property name, like window.configSettings.helloWorld, what i should be doing (which actually works perfectly) is calling it like window.configSettings.remoteActions.helloWorld

¯\_(ツ)_/¯

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.