2

Is it a requirement to have parameters or a callback function with Visualforce.remoting.Manager.invokeAction?

I would like to do something like:

function getIDA(pg_type, bureau) {
    showPGCreditLoadingIDA(pg_type, bureau, true); // Hide the panel contents and show the spinner
    Visualforce.remoting.Manager.invokeAction(
    'IDAnalyticsController.pullIDA',//this calls a webservice and handles the data needed to be displayed on the VFP
    )
}

I don't really need to handle the data with a call back function because the data is already handled in the pullIDA method. Is this not allowed?

I am getting JS error: Uncaught ReferenceError: getIDA is not defined when I do not have a callback function.

UPDATE: Visualforce.remoting.Manager.invokeAction and down is causing error: "Uncaught ReferenceError: getIDA is not defined"

function getIDA(pg_type, bureau) {
    console.log('got into ConsumerRisk JS');
    showPGCreditLoadingIDA(pg_type, bureau, true); // Hide the panel contents and show the spinner
    var pg_id = getPGIDA(pg_type);
    console.log('pg_ id : ' + pg_id);
    Visualforce.remoting.Manager.invokeAction(
    console.log('got into vf remoting invoke action');
    'IDAnalyticsController.pullIDA',//this calls a webservice and handles the data needed to be displayed on the VFP
    function(){}) //I have tried to return NULL as well
}

1 Answer 1

4

Your "trailing comma" is causing a compiler error, so your method becomes undefined. However, you need to have a callback, even if it does nothing, so just use function() { } for your second parameter.

function getIDA(pg_type, bureau) {
    showPGCreditLoadingIDA(pg_type, bureau, true); // Hide the panel contents and show the spinner
    Visualforce.remoting.Manager.invokeAction(
    'IDAnalyticsController.pullIDA',//this calls a webservice and handles the data needed to be displayed on the VFP
    function() {}
    )
}

As you can see in the documentation, the callback method is a required parameter (it is not enclosed in brackets):

[***namespace***.]controller.method(
    [parameters...,]
    callbackFunction,
    [configuration]
);
4
  • thanks for the documentation and clarification. Is it possible the Visualforce.remoting.Manager.invokeAction is written incorrectly? I am still getting an uncaught reference error when I add this part into the function. When I take it out though the function runs fine.
    – Olivia
    Commented Feb 20, 2017 at 23:01
  • @Olivia your JavaScript is still wrong. You need to pay attention to where you're inserting new code. You put a console.log inside of the parameter list, and along with the semi-colon, you confused the JS compiler again. Try using a JavaScript linter to avoid mistakes like this, or consider using some sort of JavaScript-aware IDE.
    – sfdcfox
    Commented Feb 20, 2017 at 23:19
  • oh shoot. I thought that you could use console.log anywhere through out the function. I didn't realize that Visualforce.remoting.Manager.invokeAction() was not considered JS.
    – Olivia
    Commented Feb 20, 2017 at 23:29
  • 1
    @Olivia it is JS, but you can't do something like this: someFunction( console.log(data); someparam) It's the same basic rules as Apex Code, etc. Each statement has to be written correctly.
    – sfdcfox
    Commented Feb 20, 2017 at 23:31

You must log in to answer this question.

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