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
anant Agarwal 5anant Agarwal 5 

How can we access controller variables with Javascript remoting?

Hi,

I am creating a VF page for SF1 application using HTML and apex components. Currently whenever we need to call controller method, all form data get submitted to the backend which increases network latency. To avoid that I was trying to implement Java script remoting. With Java script remoting, I found that we can't use controllers variables which stores previous values. The only option we have to use those values, return the values to the JS callback function and pass it back to remoteAction method as a parameter, which is increasing load on my SF1 application. Do we have better way to do this? Because I need to store Map<string, WrapperClass> as well as List and sObject record and above solution is not looking perfect to me.

Thanks for your help.
NagaNaga (Salesforce Developers) 
Hi Anant,

Javascript can access variables in the viewstate (controller properties) using the same notation you would use inside VF elements, BUT only if they are primitives. Complex object types (such as lists or maps) are not directly translated into the equivalent Javascript types. They are basically stored as strings in the viewstate, and Javascript doesn’t have a way of knowing that it’s, for example, a list or a map. There is no information about the data type on the client side.

If you want to transform a complex object type from its viewstate representation into Javascript you have to manually do it yourself. Let’s say for example that the controller has a property that is a map named MyMap, and that this map is created and instantiated in the controller.

Please see the link below for more information

http://developer.salesforcefoundation.org/#blog/post/2014/09/03/accessing-viewstate-from-javascript.html

Best Regards
Naga Kiran