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
schndtschndt 

Question regarding Javascript Remoting example in the VF developers guide


Hi,
I am not able to figure why the JS remoting example shown at the following location would ever work correctly.

https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_js_remoting_example.htm

Shouldn't the merge field syntax {!$RemoteAction.AccountRemoter.getAccount} _not_ be understood by Javascript?

For example,when I amend the examples as follows :

Change:
Visualforce.remoting.Manager.invokeAction(
   '{!$RemoteAction.AccountRemoter.getAccount}',
   accountName,
   function, {...});

To:

AccountRemoter.getAccount(
   accountName,
   function, {...});

It works perfectly as expected.

​What am I missing?
Best Answer chosen by schndt
Chris Gary CloudPerformerChris Gary CloudPerformer
All the {!$RemoteAction.AccountRemoter.getAccount} expressing is doing is attempting to get the reference to the Javascript generated function from the class.  Sometimes this gets confused if the class has more than one function that it could possibly reference.  Do you have another method in your class named 'GetAccount' or 'GETACCOUNT', even if it has a different set of parameters?  Sometimes, the generator can even misinterpret a property with an accessor method - for example - do you have a puplic property on your class called 'Account'? Sometimes the generator can get confused by thinking that 'getAccount' means accessing the property 'Account' rather than actually calling a method 'getAccount'.  Hope this helps.

All Answers

Chris Gary CloudPerformerChris Gary CloudPerformer
All the {!$RemoteAction.AccountRemoter.getAccount} expressing is doing is attempting to get the reference to the Javascript generated function from the class.  Sometimes this gets confused if the class has more than one function that it could possibly reference.  Do you have another method in your class named 'GetAccount' or 'GETACCOUNT', even if it has a different set of parameters?  Sometimes, the generator can even misinterpret a property with an accessor method - for example - do you have a puplic property on your class called 'Account'? Sometimes the generator can get confused by thinking that 'getAccount' means accessing the property 'Account' rather than actually calling a method 'getAccount'.  Hope this helps.
This was selected as the best answer
schndtschndt
Yup, that's what it was. I had an overloaded getter on Account which I removed. Seems to work fine now. Thanks for your help.
Chris Gary CloudPerformerChris Gary CloudPerformer
No problem.  If this solved your issue, please 'Mark as Best Answer' to mark this Question as Solved. Thanks!