Javascript remoting is one of my favourites from Spring’11 release and I’m constantly thinking of making best use of it in Visualforce. I believe remoting is the way to make Visualforce more “viewstate less”, this post shows a POC of a complete functional example of a page that searches and updates accounts using Remoting only i.e no viewstate.
In my previous post about “javascript remoting using jquery tempaltes”, we saw how we use remoting to easily render a salesforce style grid of accounts.
In this post, we will see how we can easily extend the same account grid example, to finally have following features
A account search box, that allows user to search for accounts via name. (this search is powered by Javascript Remoting)
Account records returned by Javascript remoting search are rendered into a salesforce style pageblocktable, this is done using jquery templates.
Have editable PHONE field in the account grid. When user changes any phone number in this grid its updated back on the account record in salesforce (this update is powered by Javascript Remoting)
Side note : This post requires jquery knowledge, its jquery who’s making many big things look trivial in sample code. So if you are not in LOVE with jquery, starting dating her/him

Where is the code ?
Code for both Apex Controller and Visualforce page is available on snipplr.com. If you have any comments/concerns/queries please comment back here on this post.
Remoting in Action !
Searching for accounts
Account updated on blur
So, Javascript Remoting == ViewStateLess VisualForce ?
It would be great if we can go 100% view stateless !!! but as of now, its not 100% possible to go view stateless on all fronts using Javascript Remoting.
The major reason I see is “locale specific formatting and validations”. These validations are done super smartly and silently by visualforce tags like <apex:inputField …/>. So, you have to be careful, if you are going to deal with fields like Number, Currency and Date fields in visualforce.
But, that doesn’t means we loose heart and can’t do cool things, with HTML 5 “input” tag has gone much smarter then ever before i.e. supporting phone, email etc as type.
Comments (12)
Anonymoussays:
March 25, 2011 at 2:38 pmIf only Javascript Remoting supported Collections and sObjects or even just Objects, instead of only primitive datatypes :(I don't expect to see that in Summer '11… maybe Winter?
Anonymoussays:
March 25, 2011 at 2:47 pmHey Ryan,Good News, Remoting supports Primitive/Sobject collections, please check this link : http://www.salesforce.com/us/developer/docs/pages/Content/pages_js_remoting.htm#pages_js_remotingThough nicer would be to have support for User defined Apex classes, that will allow encapsulation/aggregation of more information in one call.
Anonymoussays:
March 25, 2011 at 10:57 pmNice post. Just wanted to let you know that support for user defined Apex classes is coming in Summer '11…
Anonymoussays:
March 26, 2011 at 5:07 amHey Stephan ! Thats really exciting news, thanks for sharing 🙂
Anonymoussays:
April 11, 2011 at 6:25 pmVery good and useful post. got stumped by the limitation though (not supporting custom Apex types :(.. ). something is eating up all of my view state, so thought of going with Remoting. seems like i have to wait for a few months…
Anonymoussays:
April 12, 2011 at 5:03 amThanks Mohammad Swaleh, glad you liked the post.yeah custom apex types would be great addition to the remoting stack, I am also waiting for it to release !
Anonymoussays:
May 13, 2011 at 5:05 pmAbhinav,My inquiry as it relates to SObject/Collections was geared at the RemoteAction parameters… The ability to return SObjects and collections is great, but it would be nice to be able to pass in a Primitive Array for instance without having to .join(',') in javascript and .split(',') in apex to get a list…
Anonymoussays:
May 17, 2011 at 3:18 amRyan, thats a very good point and a genuine requirements. We should post this as an idea for enhancing the remoting api.
Anonymoussays:
November 18, 2011 at 6:05 amThank you for sharing this solution, this problem has been bothering me for some time now.us vpn
Anonymoussays:
November 18, 2011 at 7:34 amI'm glad @Timmy that this solution helped !
Anonymoussays:
May 7, 2012 at 5:11 amHi Abhinav,Is there any way to send sObject, and collections as input parameter.So far I have only sent stringified json, and parsed it back .Though the URL says its possible i could not locate any examples.http://www.salesforce.com/us/developer/docs/pages/Content/pages_js_remoting.htm#pages_js_remotingRegardsDipankar@arxxus.com
Anonymoussays:
May 7, 2012 at 5:18 amHi Dipul, Apex REST web services allow this, so same should hopefully apply here.