Get Started with Salesforce Mobile SDK

Learning Objectives

After completing this unit, you'll be able to:

  • Understand the various models (native, HTML, and hybrid) for Salesforce Mobile SDK app development.
  • Compare the relative advantages and disadvantages of each approach.

Introduction to Salesforce Mobile SDK Development

In a short time, mobile devices have become indispensable to our personal and professional lives. People of every stripe create and consume data on an ever-increasing variety of connected devices. Workers use smart devices to stay in touch with each other, make deals with customers, and engage the public on social networks.

To meet the challenge of running businesses on mobile devices, Salesforce provides the Salesforce Platform. This platform guarantees enterprise-grade reliability, availability, and security across a wide range of mobile technology.

Salesforce Platform offers many options for building and deploying mobile applications. The two most basic and comprehensive of these options are the Salesforce Application and Salesforce Mobile SDK.

  • The Salesforce app, available on Apple AppStore and Google Play Store, delivers the fastest way for Salesforce platform administrators and developers to build and deliver apps for employees. It offers simple point-and-click tools for administrators and the Lightning web development platform for advanced developers. This trail doesn’t address Salesforce application development.
  • Salesforce Mobile SDK gives developers the tools to build mobile applications with customized user experiences. Mobile SDK lets you produce stand-alone custom apps that you distribute through the Apple App Store or Google Play Store. These apps can target employees, customers, or partners. You can choose native or web technologies to build these apps while enjoying the same grade of reliability and security found in the Salesforce app.

In this module, you’ll get started with Mobile SDK app development.

Mobile SDK harnesses platform technology for a complete mobile development experience. Its modular architecture provides features and services such as:

Enterprise Identity & Security
Mobile SDK includes a complete implementation of Salesforce Connected App Policy, so that all users can access their data securely and easily. It supports SAML and advanced authentication flows so that administrators always have full control over data access.
SmartStore Encrypted Database
Mobile databases are useful for building highly responsive apps that also work in any network condition. SmartStore provides an easy way to store and retrieve data locally while supporting a flexible data model. It also uses AES-256 encryption to ensure that your data is always protected.
SmartSync Data Framework
SmartSync Data Framework provides a simple API for synchronizing data between your offline database and the Salesforce cloud. With SmartSync Data Framework, developers can focus on the UI and business logic of their application while leaving the complex synchronization logic to Mobile SDK.
Mobile Services
Mobile SDK supports a wide range of platform mobile services, including push notifications, geolocation, analytics, collaboration tools, and business logic in the cloud. These services can supercharge your mobile application and also reduce development time.
Salesforce Communities
With Salesforce Communities and Mobile SDK, developers can build mobile applications that target their customers and partners. These applications benefit from the same enterprise features and reliability as employee apps.
Native and Hybrid, iOS and Android
Mobile SDK lets you choose any technology (native, React Native, or Cordova-based hybrid apps) on iOS and Android.

About Native, HTML, and Hybrid Development

Salesforce Mobile SDK supports several platforms for creating mobile apps:
  • Native apps are specific to a given mobile platform (iOS or Android). These apps use the development tools and languages that the respective platform supports. For example, you develop iOS apps in Xcode using Objective-C or Swift. Native apps look and perform best but require the most development effort.
  • HTML5 apps use standard web technologies—typically HTML5, JavaScript, and CSS—to deliver apps through a mobile web browser. This “write once, run anywhere” approach to mobile development creates cross-platform mobile applications that work on multiple devices. While developers can create sophisticated apps with HTML5 and JavaScript alone, some challenges remain. For example, session management, secure offline storage, and access to native device features can pose problems.
  • Hybrid apps combine the ease of HTML5 web app development with the power of the native platform by wrapping a web app inside the Salesforce container. This combined approach produces an application that accesses the device’s native capabilities and is delivered through the app store. You can also create hybrid apps using Visualforce pages delivered through the Salesforce hybrid container.
  • React Native apps use the React Native framework from Facebook, Inc., to run JavaScript apps as native code. Rather than following the hybrid paradigm, React Native lets you assemble the native UI building blocks with JavaScript code. This framework provides direct access to native resources and lets you test without recompiling. In performance terms, React Native runs a close second to pure native execution.

Native Apps

Native apps provide the best usability, the best features, and the best overall mobile experience. There are some things you get only with native apps:

  • Fast graphics API—The native platform gives you the fastest graphics. This advantage comes into play, for example, if you’re using larges quantities of data and require a fast refresh.
  • Fluid animation—Related to the fast graphics API is the ability to have fluid animation. This ability is especially important in gaming, highly interactive reporting, or intensely computational algorithms for transforming photos and sounds.
  • Built-in components—The camera, address book, geolocation, and other features native to the device can be seamlessly integrated into mobile apps. Another important built-in component is encrypted storage, but more about that later.
  • Ease of use—The native platform is what people are accustomed to. When you add that familiarity to the native features they expect, your app becomes that much easier to use.
Native app development requires an integrated development environment (IDE). IDEs provide tools for building, debugging, project management, version control, and other tools professional developers need. You need these tools because native apps are more difficult to develop. Likewise, the required level of experience is higher than in other development scenarios. If you’re a professional developer, however, you don’t have to be sold on the benefits of
  • Proven APIs and frameworks
  • Painless special effects through established components
  • Maintaining all your code in one place

HTML5 Apps

An HTML5 mobile app is essentially one or more web pages that are designed to work on a small mobile device screen. As such, HTML5 apps are device agnostic and can be opened with any modern mobile browser. Because your content is on the web, it’s searchable, which can be a huge benefit for certain types of apps (shopping, for example).

Getting started with HTML5 is easier than with native or hybrid development. Unfortunately, every mobile device seems to have its own idea of what constitutes usable screen size and resolution. This diversity imposes an extra burden of testing on different devices and different operating systems.

An important part of the "write once, run anywhere" HTML5 methodology is that distribution and support are much easier than for native apps. Need to make a bug fix or add features? Done and deployed for all users. Native app, on the other hand, require longer development and testing cycles. Furthermore, customers typically have to log in to an app store to get new versions.

If HTML5 apps are easier to develop, easier to support, and can reach the widest range of devices, what are the drawbacks?
  • No secure offline storage—HTML5 browsers support offline databases and caching, but with no out-of-the-box encryption support. You get all three features in Mobile SDK native applications.
  • Unfriendly security features—Trivial security measures can pose complex implementation challenges in mobile web apps. They can also be painful for users. For example, a web app with authentication requires users to enter their credentials every time the app restarts or returns from a background state.
  • Limited native features—The camera, address book, and other native features are accessible on few, if any, browser platforms.
  • Lack of native look and feel—HTML5 can only emulate the native look, and customers can’t use familiar compound gestures.

Hybrid Apps

Hybrid apps are built using HTML5 and JavaScript wrapped inside a thin container that provides access to native platform features. Generally, hybrid apps provide the best of both HTML5 and native worlds. They’re almost as easy to develop as HTML5 apps and can access all the functionality of native. In addition, hybrid apps can use the Mobile SDK SmartSync Data Framework feature to
  • Model, query, search, and edit Salesforce data.
  • Securely cache Salesforce data for offline use.
  • Synchronize locally cached data with the Salesforce server.

You know that native apps are installed on the device, while HTML5 apps reside on a web server. Perhaps you’re wondering whether hybrid apps store their files on the device or on a server. Great question! The storage location depends on whether your hybrid app is local or remote.

Local
You can package HTML and JavaScript code inside the mobile application binary, in a structure similar to a native application. You use REST APIs and Ajax to move data back and forth between the device and the cloud.
Remote
Alternatively, you can implement the full web application from the server (with optional caching for better performance). Your container app retrieves the full application from the server and displays it in a native web view.

Both types of hybrid development are covered here.

React Native Apps

React Native apps use specialized scripting languages.
  • JavaScript is ES2015.
  • CSS is JavaScript code that closely resembles CSS syntax and is typically written inline in your JavaScript app.
  • Markup is actually a special flavor of XML named JSX. Unlike HTML, which embeds JavaScript in markup, you embed JSX markup in JavaScript.
In addition, React Native bridges provide access to standard Mobile SDK features, such as:
  • SmartStore
  • SmartSync Data Framework
  • Salesforce login and authentication
  • Salesforce REST API access.
You can even access your own native objects—in Objective-C, Swift, or Java—directly in React Native code.

Mobile Architecture Comparison

The following table shows how the various development scenarios stack up.

Native, React Native HTML5 Hybrid
Graphics Native APIs HTML, Canvas, SVG HTML, Canvas, SVG
Performance Fastest Fast Moderately fast
Look and feel Native Emulated Emulated
Distribution App store Web App store
Camera Yes Browser dependent Yes
Notifications Yes No Yes
Contacts, calendar Yes No Yes
Offline storage Secure file system Not secure; shared SQL, Key-Value stores Secure file system; shared SQL (through Cordova plug-ins)
Geolocation Yes Yes Yes
Swipe Yes Yes Yes
Pinch, spread Yes Yes Yes
Connectivity Online, offline Mostly online Online, offline
Development skills Objective-C, Swift, Java, Kotlin; JavaScript (React Native only) HTML5, CSS, JavaScript HTML5, CSS, JavaScript
retargeting