5

I am displaying multiple popups( Tool tips)  on different visualforce pages and each popup has close button. By clicking on close button i need to call controller and perform DML operation in multiple pages. 

I have tried calling controller with Remote action from JavaScript ( JavaScript uploaded in Static Resource) since it is very large lines of code. I am not same controller from JavaScript when user is different pages. Below is the code i have tried calling controller from JavaScript. I am getting method not defined error.

Visualforce.remoting.Manager.invokeAction(
    '{!$RemoteAction.MSSPageController.updateHopscotch}',
        function(result, event){
        alert(result);
        flag = result;
        console.log('Log here===='+result);
        }
);

Thanks,

​Anil Kumar 

  • 2
    You won't be able to achieve this with javascript remoting. Javascript remoting is only supposed call its only page's controller's action. Why do you want to call other's page's server method? – Lance Shi Aug 4 '16 at 5:52
  • I want to perform DML operation and update the database instead of writing multiple methods in multiple classes i would like to write one method for all the pages Remote Calls. – anil kumar Aug 4 '16 at 7:26
  • 1
    Exactly for that kind of scenarios, extensions has been invented. Make your all logic in all class, and define it as an extension to your pages – kurunve Aug 4 '16 at 8:11
2

You can use the Window Variable in your page and later read from there

In your visualforce page add this

<script>
        configSettings = {
            remoteActions: {
                updateHopscothc: '{!$RemoteAction.MSSPageController.updateHopscotch}'
            }

        }
    </script>

In your static resource you will just call this like

Visualforce.remoting.Manager.invokeAction(
configSettings.remoteActions.updateHopscothc,
    function(result, event){
    alert(result);
    flag = result;
    console.log('Log here===='+result);
    }
);
|improve this answer|||||
0

Had the same problem.

The problem is because you're uploading the javaScript file via static resource, but all {!####} expressions (in this case your method's name) are been compiled on page load and not in the static resource.

My solution:

Add the remote action name as a hidden input field on the page, like this:

<input id="remote_action" type="hidden" value="{!$RemoteAction.MSSPageController.updateHopscotch}"/>

And then fetch the value of the input by the Id and pass it to the remote manager.

Hope I've helped.

|improve this answer|||||
0

This should work:

MSSPageController.updateHopscotch( function(result, event){ alert(result); flag = result; console.log('Log here===='+result); } );

|improve this answer|||||
  • Excuse me for the formatting – Craig Lobo Mar 24 at 12:08

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.