You need to sign in to do that
Don't have an account?
Remoting with multiple arguments using Visualforce.remoting.Manager.invokeAction
Hi,
I am attempting to use the new $RemoteAction variable and Visualforce.remoting.Manager.invokeAction() function in the summer 12 release.
I have successfully used them to call a remote action function when that function takes a single argument as its input, e.g.
Visualforce.remoting.Manager.invokeAction('{!$RemoteAction.RemoteController.test1Str}','1 argument', handleReturn,{escape: true});
I have methods currently working in salesforce which accept 0 and 2 or more arguments. The obvious way of calling these to me would be to simply include the arguments separated by commas as that is what is done with the current calls, e.g.
RemoteController.test0Str( handleReturn,{escape: true})
would map to
Visualforce.remoting.Manager.invokeAction('{!$RemoteAction.RemoteController.test0Str}', handleReturn,{escape: true});
and likewise for 2 arguments:
RemoteController.test2Str('2','arguments', handleReturn,{escape: true})
Visualforce.remoting.Manager.invokeAction('RemoteController.test2Str','2','arguments', handleReturn,{escape: true})
But for these two cases I get the following logged to the JS console:
Visualforce Remoting: Parameter length does not match remote action parameters: expected 0 parameters, got Visualforce Remoting: Parameter length does not match remote action parameters: expected 2 parameters, got
So it is clear that salesforce know what it is expecting, but it is not clear how I pass the arguments.
I have also attempted passing the arguments as an array ,e.g.
[] ['1 argument'] ['2','arguments']
and (in desparation) as a single object with the argument names as the parameter names! None of this works.
Has anyone had any success using remoting in this fashion? There is a gist of my code at https://gist.github.com/2713502.
Regards,
James
Class
@RemoteAction
global static Account getAccount(String accountName1 , String accountName2)
{
Page:-
MyJSController.getAccount(accountName1, accountName2, function(result, event){
U can try this
If this won't work just send a single comman sparated aregument in string & split them in apex code
This is likely a bug. As a workaround, can you group arugments into a single parameter? Or call RemoteController.test2Str directly.
This will be fixed.
Hi SRK,
THanks for your response
The reason I want to use the $RemoteAction variable and Visualforce.remoting.Manager.invokeAction() function is that this code is destined to be used in a managed package. With these new features it should mean that developers working in unmanaged versions of the code do not need to change the code to account for namespaces as they check it in and out, or write kludgy javascript to handle the namespaces. Hoping SFDC will fix this.
Regards,
Jaes
Hi cwall, thanks for your response.
I will log a case with salesforce regarding this.
Regards, James
I too was struggling with this today, what i ended up trying after trying an array or json object (neither worked) was seperating the parameters, with a comma, like this:
where 'param1' and the current page parameter are both parametrs of the method 'testMethod'. As for passing 0 parameters, im not sure, but this certianly worked for passing 2. Hope this helps!
If one of the variables being passed using the remoting manager are undefined, you will get an error. It's better to set a global variable and check for undefined prior to calling the RemoteAction.
If the variables are supposed to be a Decimal and you have declared them as a string in your class, it will also return an error. So check that your variables match.