3

Having a page that uses AngularJS with Remote Actions to manipulate data, I'm facing an issue while trying to save the data to the server.

I have a method on the controller that receives two String parameters that are two lists of objects serialized as JSON. The method's signature looks like this:

global static void save(String receipts, String items)

Of course, it has the @RemoteAction annotation.

My issue is one the page's JavaScript. I try to pass the two parameters on a list, but Salesforce keeps giving me an error on the console:

Visualforce Remoting: Parameter length does not match remote action parameters: expected 2 parameters, got

I'm trying to pass a list with the two serialized lists as the invokeAction function parameter:

Visualforce.remoting.Manager.invokeAction(
  '{!$RemoteAction.ReceiveItemsController.save}',
    [JSON.stringify(list_a), JSON.stringify(list_b)],
    function (result, event) {
      if (event.statusCode == 200) {
        // yay!
      }
    }, { escape : false })

The documentation specifies the call like this:

[***namespace***.]controller.method(
    [parameters...,]
    callbackFunction,
    [configuration]
);

And specifies that parameters is...

A comma-separated list of parameters that your method takes.

So what is wrong with my code?

1 Answer 1

4

[ (square brackets) are not needed to enclose parameters.

Visualforce.remoting.Manager.invokeAction(
  '{!$RemoteAction.ReceiveItemsController.save}',
    JSON.stringify(list_a), JSON.stringify(list_b),
    function (result, event) {
      if (event.statusCode == 200) {
        // yay!
      }
    }, { escape : false })
1
  • 1
    The part "list of parameters" can get really confusing. I thought it was literally a list of parameters, not the parameters after the method and before the callback function. Thank you Ashwani! Commented May 2, 2017 at 17:06

You must log in to answer this question.

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