2

I know it is possible to leverage existing visualforce pages in a hybrid mobile app, but is it possible to use the javascript association with those pages? For example if I pull down a VF page with javascript using the sforce object what will happen if i invoke that javascript? Will it work as expected? Will remoting work?

What about if the VF page is cached and the app is offline? Will I need to write a separate controller for offline scenario and check for being online?

1

When building a hybrid mobile app using Visualforce with offline support, you'll need to address:

  1. Displaying Visualforce pages offline

  2. Managing session expiration

  3. Offline data storage

You can use the html5 application cache to cache your Visualforce page and its resources for offline use. You probably don't want to use JS Remoting because it injects Salesforce libraries into your page for which you can't control the URLs, and therefore can't reliably cache. Start with a Visualforce page with the Salesforce header and stylesheets disabled, and with a cache manifest, which can be another Visualforce page:

<apex:page showHeader="false" standardStylesheets="false" cache="false" doctype="html-5.0" controller="MyController">
<html manifest="/apex/cache_manifest">

Instead of JS Remoting, use ForceTK, which you can store in a static resource:

<script src="{!URLFOR($Resource.MobileApp, '/lib/forcetk.js')}"></script>

and add it to your cache manifest:

<apex:page showHeader="false" standardStylesheets="false" contentType="text/cache-manifest" cache="false" controller="MyController">CACHE MANIFEST

CACHE:
{!URLFOR($Resource.MobileApp, '/lib/forcetk.js')}

Use the OAuth plugin included with the Salesforce Mobile SDK to refresh the session when it expires. ForceTK will try to refresh the session token after it expires, but it won't work on a Visualforce page because you need to refresh the Visualforce session first. See https://salesforce.stackexchange.com/a/31687/240.

SmartStore is a good place to start for offline storage. If you're using Backbone, SmartSync provides support for offline caching using SmartStore. Depending on how much data you need to cache, you might be able to get by with LocalStorage.

1
  • Based on the question, I interpreted Salesforce1 as the-platform-formerly-known-as-force.com, rather than the-web-app-formerly-known-as-salesforce-touch.
    – xn.
    Aug 7 '14 at 21:45
0

I created a hybrid mobile-app for one of my clients using VF and jquery mobile. All the data is fetched by JS Remoting and then served up in the app.

For my app, I specifically needed to have offline storing as it is for service technicians in the field who might not have an active connection at all times. Your pages will not automatically be cached, you need to provide some kind of mechanism for the data to be persistent between pages.

What I did was, I implemented a Data Structure using IndexedDB (Browser storage space) which saved all the relevant data for most important part ( Active case for instance) and as soon as the the app was online, the data was pushed to server and on success response, the localstorage was cleared off.

Storing data locally also reduced the number of round-trips to the server which also provide better performance in the app.

Hope it helps, if not, hit me up and can provide you more details.

7
  • so the visualforce pages and js was cached... Did the JS remoting (to access the controller) in the vf page not execute when offline? how is that scenario handled? can you use smartstore?
    – user8560
    Aug 7 '14 at 10:50
  • JS Remoting is an POST call to fetch data from the server. When the device is offline, the POST call cannot be made. That is why I am saving the data in the local database. Aug 7 '14 at 11:01
  • Right, but in your code (within the cached vf page) do you need to make a distinction? Will the code try to execute and throw an error when offline?
    – user8560
    Aug 7 '14 at 11:08
  • This is for my use case: I search if the device is offline and serve the data from local storage, if online fetch from server. if it's loading the first time and can't connect, then it throws an error. Aug 7 '14 at 11:21
  • Can you use smartstore instead of index db?
    – user8560
    Aug 7 '14 at 11:34
0

Everything should work as expected, but you'll never be sure until you try it out yourself -- the proof is in the pudding. (And pudding is so tasty.)

The Docs, http://www.salesforce.com/us/developer/docs/salesforce1/salesforce1_guide.pdf, has VF Examples using JavaScript. And since the VF Pages are the same 'ole VF Pages using controllers and standardControllers, any JS Remoting will work too.


Update

A similar question was asked, and "it appears that Salesforce1 doesn't like operating offline."

Offline storage for Visualforce pages in Salesforce1

1
  • so will these pages not work if the page is cached? or will i need to write a separate controller for when the app is offline
    – user8560
    Aug 7 '14 at 1:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.