This is the third article in a series focused on Angular 2 and Ionic 2. In Part 1, I shared a first version of the Ionic Realty application using a set of mock data services. In Part 2, I used actual REST services powered by a Node.js back-end. In this article, I share a version of Ionic Realty connecting to a Salesforce back-end instead of a Node.js back-end. The Ionic application uses OAuth and the Salesforce REST services to access data.
Watch the video (the second part covers the Salesforce integration):
The source code for the application is available in this repository.
- The client application remains mostly unchanged. Only the internal implementation of the data services changes.
- The client application uses the ECMAScript 6 version of forcejs to authenticate with OAuth and call Salesforce REST services.
- I’m using promises instead of observables in this version of the app. That’s mostly because forcejs was written to work with promises. However the forcejs promises could easily be turned into observables. See Part 2 of this series for more information on promises and observables.
- You can run the app transparently in the browser and in Cordova using the Salesforce Mobile SDK OAuth plugin (see installation instructions below).
- In a real life application, it would make more sense to login to a Salesforce Community since Ionic Realty is a customer-facing application. You could then also provide a branded login experience.
Salesforce App Cloud
This is beyond the scope of this article, but some of the advantages of using the Salesforce App Cloud for this application include:
- You don’t need to write server code. You create the objects needed for your app (in this case: brokers, properties, and favorites) in Salesforce and a customizable UI that users can use to manage the data (create, update, delete brokers and properties) is automatically available.
- The objects you create are automatically exposed through a REST API.
- Your custom application data can tightly integrate with existing Salesforce data (contacts, opportunities, leads, etc).
- You can leverage Salesforce’s trusted identity and security features.
- You can leverage many other built-in features: reports, analytics, etc.
To install the Salesforce side of the application:
- If you don’t already have a Salesforce Developer Environment, sign up for a free Developer Edition here.
- Click this link to install the Realty unmanaged package in your developer org. The package installs custom objects (Property, Broker, and Favorite) along with layout customizations, tabs, and a Visualforce page to generate sample data.
- In the Developer Console, open the RealtyDataLoader Visualforce page, click Preview, and then click Load Sample Data to load sample data in the Property and Broker objects.
- Access the Properties and Brokers tabs to browse sample properties and brokers and familiarize yourself with the data.
To create the Ionic application:
- Install the latest version of Cordova:
npm install -g cordova
sudo npm install -g cordova
- Install Ionic 2 beta:
npm install -g ionic@beta
sudo npm install -g ionic@beta
- Clone the project repository
git clone https://github.com/ccoenraets/ionic2-realty-salesforce
- Navigate to the ionic2-realty-salesforce directory
- Install the dependencies
To run the application in the browser:
- On the command line, navigate to the ionic2-realty-salesforce directory
To build and run the application on device:
- Add the iOS platform:
cordova platform add firstname.lastname@example.org
- Add the Salesforce Mobile SDK plugin:
cordova plugin add https://github.com/forcedotcom/SalesforceMobileSDK-CordovaPlugin
- Build the native app:
cordova build ios
- Open the .xcodeproj in the platforms/ios and run the app on device or in an emulator.