I am going to come right out and say I heart jQuery Mobile; it just makes creating a mobile device friendly page a snap. Yesterday, I was in Boston at one of our Developer Workshops where we spend a day with a bunch of developers talking about the Force.com platform. Typical me decided mid-morning that I wanted to change up some of the content for one of the afternoon sessions. The session I was going to present was covering Force.com Sites. My fear was that the session didn’t highlight how well the cloud and mobile development can go together. In particular, how the folks in the room could leverage their new found Visualforce and Apex awesomeness that we covered in the morning sessions.

Long story short, I threw together some very quick Visualforce pages which used jQuery Mobile to render the pages nicely on any mobile device. Here is all you need to do:

1. Add the jQuery Mobile libraries and CSS as static resources (or you can also refer directly to the libraries on the jQuery Mobile home page) under Setup –> Develop –> Static Resources. I like to bundle all my dependencies in a zip and refer to that bundle going forward. (see below)

2. Create my listings page. I was demoing the Big Cloud Realty Sites app (you can see it live here) which uses a real estate example. My goal was to show the current listings in a nice mobile friendly way.  Here is my listings Visualforce page with jQuery Mobile markup. Note the references to my jQuery Mobile bundles from step one. The rest of the jQuery Mobile magic is handled by the data-role divs and additional data-xxx attributes.

3. A listings page without a detail page isn’t very exciting, so I added quick details page:

And, that’s it. As you can see from the code examples, 90% of everything is standard Visualforce, the rest is HTML markup.

With my funky new mobile page, I added an additional link to the Big Cloud Sites template, and we were good to go in less than an hour. But the proof is in the pudding, as they say. Go ahead and try it for yourself. Go to the Big Cloud Sites page, and click on the mobile link on your mobile device.

Get the latest Salesforce Developer blog posts and podcast episodes via Slack or RSS.

Add to Slack Subscribe to RSS