When to use Apex controller vs JS Remoting or REST

There's no one true path! But you've already touched on a couple interesting points like the historical availability of Visualforce on various devices.

I like to compare and contrast from the perspective of developer and user:

Apex and Visualforce:

  • offers the lowest barrier to entry for developers,
  • guaranteed forward compatibility on all browsers,
  • powerful enough to cover 90% of business requirements,
  • exposed to more devices in future without redevelopment,

Service orientation vs CRUD orientation

  • CRUD is easy to handle in VF without ANY apex
  • more servicey APIs can be consumed by ANY JavaScript framework,

High responsiveness or perception of responsiveness

  • if you desire cutting edge snappiness < 300ms, you have to go stateless,
  • non VF clients have more control over comms and UI, otherwise these are coupled,

Governor limit usage in the host org

  • if you can't deploy code to the org, you must use the REST API, not VF
  • JavaScript Remoting is ungoverned and you can hit it as much as you like,

Future state of the platform

  • Salesforce can already scaffold significant proportion of UI from data model,
  • similarly, they could, at will, generate mobile-optimised outputs from your VF,

If you want the slickest, most responsive, latest and greatest interface for your special requirement NOW, you have to build it and maintain it.

If you are can't afford to maintain your interfaces, build them in VF. You will be happy with the consistency and usability.

If your requirements are highly specialised (drag and drop, two way sockets, pixel perfection according to your designer etc) you have no choice but to go full custom.

Just know that if you do go full custom, Salesforce are the Rolls Royce of APIs (JavaScript Remoting, REST, Streaming API) that you can use to build your front ends.


For Mobile Hybrid server side model i prefer Javascript remoting in apex controllers rather than using the Visualforce common tags .

At max i can use repeater in apex apex:repeat and will use Angular.Js ,Backbone or jquery to do dom manipulation .

The apex and Visualforce works on concept of getters ,setters and actionFunctions and for action Function to use and ReRender a block we have to use Visualforce Markup and those are heavy tags not designed for mobile browser .

So the best approach is to use some Javascript framework and manipulate the DOM on the fly .

Frameworks like angular or backbone make it more easier to write this DOM manipulation logic .While Jquery has smaller learning curve and really effective in DOM manipulation.

Hence using apex controller and visualforce Tags is less preferred .Use apex controllers to write Javascript remoting and this provides result in callback and on success you can write your DOM manipulation logic to show the results .