When to use Apex controller vs JS Remoting or REST

When developing a website or mobile hybrid application, what are the benefits of using the standard VisualForce page + Apex Controller design versus using a framework like AngularJS for controller functionality together with Javascript remoting and/or the Salesforce REST API?

I gather that in the case of a hybrid local app, visualforce pages are not available, so I’m assuming that in this case there is no choice but to use alternatives like the REST API, remoting and the like. If this is the case then functionality-wise there shouldn’t be anything missing, so what would be the reason for not doing things the same way in all contexts?

Answer

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.

Attribution
Source : Link , Question Author : Valyrion , Answer Author : Community

Leave a Comment