function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
CryptokiCryptoki 

Pass unknown number of parameters to JavaScript Remoting

Hi guys,

Is there a way to pass an unknown number of parameters (variable "args" below) to JavaScript Remoting like:
 
function remoting(target, ...args) {
    Visualforce.remoting.Manager.invokeAction(
        configSettings.remoteActions[target],
        args,
        function (result, event) {
            if (event.status)
                console.log(result);
        },
        { escape: false }
    );
}

Thanks!
 
AngrySlothAngrySloth
If args is a key/value object you could convert it to JSON in JS and deserialize it to a Map<String, String> in apex:
 
// Javascript

var args = {
  arg1: 'test',
  arg2: 'something else',
  arg3: 30
};


function remoting(target, ...args) {
    Visualforce.remoting.Manager.invokeAction(
        configSettings.remoteActions[target],
        JSON.stringify(args),
        function (result, event) {
            if (event.status)
                console.log(result);
        },
        { escape: false }
    );
}


// APEX

@RemoteAction
public static void theTargetMethod( String args )
{
  Map<String, String> argsObject = (Map<String, String>)JSON.deserialize( args, Map<String, String>.class );
}

Hope that helps