An Example of Using Visualforce Remote Objects with jQuery Mobile
Visualforce Remote Objects is designed to “blend” well with JavaScript frameworks. This extended but simple example shows how to use Remote Objects with jQuery Mobile to view a list of contacts and to add, edit, and delete them.
This example uses jQuery Mobile from the Salesforce Mobile Packs and is based on sample code that is included with the Mobile Pack for jQuery. Remote Objects and jQuery Mobile make it easy to create a simple contact manager page for a phone.
Note that although all four Remote Objects operations are demonstrated, there are only three callback handlers.
getAllContacts()callsretrieve()to load a list of contacts and provides an anonymous function for the callback. The callback checks for errors and then iterates through the results, adding them to the page.- Similarly,
showDetailView()callsretrieve()to load a single contact for the detail page, and the results are also handled by an anonymous function. addUpdateContact()anddeleteContact()handle adding, updating, and deleting contacts. Both methods passupdateCallback()as the callback function.updateCallback()doesn’t use the results of the Remote Objects operation. It only checks for errors, logs them to the console, and then callsgetAllContacts()to refresh the page.