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
jamesmelvjamesmelv 

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

SRKSRK

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

cwall_sfdccwall_sfdc

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.

jamesmelvjamesmelv

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

jamesmelvjamesmelv

Hi cwall, thanks for your response.

 

I will log a case with salesforce regarding this.

 

Regards, James

jlangjlang

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:

 

Visualforce.remoting.Manager.invokeAction(
'{!$RemoteAction.testClass.testMethod}',
param1,"{!$CurrentPage.parameters.Id}",
function(result){

//do callback
});
}

 

 

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!

Florian Marx05282918216679144Florian Marx05282918216679144
Unfortunately I´m having the identical issue these days. As almost 2 years went by i cannot believe that this bug was not fixed yet. Has anyone in the audience an updated status / fix idea on this issue? Any help would be greatly appreciated.
jdance1.3948195933250098E12jdance1.3948195933250098E12
I am also having issues passing in multiple parameters with javascript remoting. Will try jlang's solution. Mind boggling that this is still an issue. 
jdance1.3948195933250098E12jdance1.3948195933250098E12
Visualforce.remoting.Manager.invokeAction(
    '{!$RemoteAction.TestExtension.getAccount}',
    searchDropdownCategory, searchBoxValue,
    function(result, event){
}
Found that just passing in multiple parameters seperated by commas worked, as in jlang's example. 
Eva DeLoriolEva DeLoriol
Make sure the arguments in the javascript call match the arguments in your @RemoteAction in your Apex Class.  

@RemoteAction
    // Find accounts nearest a geolocation - called from JS on page - global for Mobile
    global static List<Account> getAccounts(String lat, String lon, Decimal miles, String houseacct) {
    string buildQuery = '';
Visualforce.remoting.Manager.invokeAction('{!$RemoteAction.FindNearby.getAccounts}',
                     lat, lon, miles, houseacct,
                         function(result, event){ ....

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(houseacct == undefined){
    houseacct = false;
    }

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.