This repository contains JavaScript libraries and Cordova plugin source code that are shared across the Hybrid Mobile SDK implementations for iOS and Android.
The Shared repository provides the JavaScript layer for Cordova-based hybrid applications that integrate with the Salesforce platform. It serves as a submodule dependency for both the iOS and Android hybrid implementations.
SalesforceMobileSDK-Shared (source of truth)
│
┌──────┴──────┐
│ │
▼ ▼
Android (submodule) iOS-Hybrid (submodule)
│ │
└──────┬──────┘
│
▼
CordovaPlugin
(copies files)
│
▼
Hybrid Templates
This repo is included as a git submodule in:
- SalesforceMobileSDK-Android at
external/shared/ - SalesforceMobileSDK-iOS-Hybrid at
external/shared/
Contains all the Salesforce Mobile SDK JavaScript libraries:
cordova.force.js
- Cordova plugins for OAuth, SmartStore, MobileSync, and SDKInfo
- Bridges JavaScript to native iOS and Android implementations
- Include after
cordova.jsin your HTML application
force.js
- Callback-based REST API client for Salesforce
- Query, create, update, delete, and upsert operations
- SOQL and SOSL query support
- Automatic token refresh
force+files.js
- File upload and download utilities
- Integration with Salesforce Files (Chatter Files)
- Base64 encoding/decoding helpers
force+promise.js
- Promise-based wrapper around force.js
- Modern async/await compatible API
- Preferred for new development
mobilesync.js
- High-level data synchronization framework
- Bidirectional sync between SmartStore and Salesforce
- Conflict detection and resolution
- Depends on force.js, cordova.force.js, underscore.js, and backbone.js
<!DOCTYPE html>
<html>
<head>
<script src="cordova.js"></script>
<script src="cordova.force.js"></script>
<script src="force.js"></script>
<script src="mobilesync.js"></script>
</head>
<body>
<script>
// Query Salesforce
force.query('SELECT Id, Name FROM Account LIMIT 10',
function(response) {
console.log('Found ' + response.totalSize + ' accounts');
},
function(error) {
console.error('Query failed:', error);
}
);
// Or use promises
force.query('SELECT Id, Name FROM Contact')
.then(function(response) {
console.log('Contacts:', response.records);
});
</script>
</body>
</html>Contains comprehensive test suites for the JavaScript libraries:
test.html
- HTML test runner page
- Can run in browser (with mocks) or Cordova WebView (with real plugins)
Test Infrastructure:
SFTestSuite.js- Base test frameworkSFAbstractSmartStoreTestSuite.js- SmartStore test base classMockCordova.js- Mock Cordova for browser testingMockSmartStore.js- Mock SmartStore pluginMockMobileSyncPlugin.js- Mock MobileSync plugin
Test Suites:
SFSmartStoreTestSuite.js- SmartStore CRUD, indexing, and Smart SQL testsSFSmartStoreLoadTestSuite.js- SmartStore performance testsSFMobileSyncTestSuite.js- MobileSync synchronization tests
In a browser (uses mocks for Cordova plugins):
open test/test.htmlIn a Cordova app (uses real native plugins):
- Create a hybrid app using templates
- Copy
test/test.htmlto the app'swww/directory - Run the app on a device or simulator
Demo applications showcasing SDK features:
| Sample | Description |
|---|---|
| mobilesyncexplorer | Complete MobileSync demo with offline sync |
| smartstoreexplorer | SmartStore operations and Smart SQL queries |
| accounteditor | CRUD operations on Account records |
| contactexplorer | Contact list browser with search |
| fileexplorer | File upload/download operations |
| userlist | User list with Salesforce data |
| usersearch | User search functionality |
| userandgroupsearch | Combined user and group search |
| simplesyncreact | React-based sync sample |
| vfconnector | Visualforce connector sample |
Samples are designed to run in a Cordova environment:
- Create a hybrid app using the SDK templates
- Replace the
www/directory content with sample code - Build and run on iOS or Android device/simulator
Third-party JavaScript libraries used by the SDK:
- backbone - MVC framework (required by mobilesync.js)
- underscore - Utility library (required by mobilesync.js and Backbone)
- jquery - DOM manipulation and AJAX
- promise-polyfill - Promise support for older browsers
- qunit - Unit testing framework
- react - UI framework (for React samples)
- ratchet - Mobile UI framework
- fastclick - Touch event optimization for mobile
- Git: Required for cloning and submodule management
- Text editor: Any editor for JavaScript development
- Web browser: For running tests with mocks
- Cordova environment: For testing with real plugins (iOS/Android)
- Clone the repository:
git clone https://github.com/forcedotcom/SalesforceMobileSDK-Shared.git
cd SalesforceMobileSDK-Shared-
Make changes to JavaScript files in
libs/ -
Test in browser:
open test/test.html-
Test in iOS/Android:
- Update submodule in iOS-Hybrid or Android repository
- Build and test in actual hybrid app
-
Commit and push:
git add .
git commit -m "Description of changes"
git push origin devAfter changes are merged, dependent repositories must update their submodules:
In iOS-Hybrid or Android repos:
cd external/shared
git checkout dev
git pull origin dev
cd ../..
git add external/shared
git commit -m "Update Shared submodule"The SalesforceMobileSDK-CordovaPlugin repository uses a script to copy files from this repo (and others) to create the final Cordova plugin package:
cd SalesforceMobileSDK-CordovaPlugin
./tools/update.sh -b dev -o allThis copies JavaScript libraries from libs/ to the Cordova plugin's www/ directory.
| Shared SDK | iOS SDK | Android SDK | Cordova iOS | Cordova Android |
|---|---|---|---|---|
| 13.2.0 | 13.2.0 | 13.2.0 | 7.1.1 | 14.0.1 |
| 13.1.0 | 13.1.0 | 13.1.0 | 7.1.0 | 13.0.0 |
| 13.0.0 | 13.0.0 | 13.0.0 | 7.1.0 | 13.0.0 |
See release notes for detailed version history.
- Mobile SDK Development Guide: https://developer.salesforce.com/docs/platform/mobile-sdk/guide
- Mobile SDK Trail: https://trailhead.salesforce.com/trails/mobile_sdk_intro
- Cordova Documentation: https://cordova.apache.org/docs/
- iOS Hybrid: https://github.com/forcedotcom/SalesforceMobileSDK-iOS-Hybrid
- Android: https://github.com/forcedotcom/SalesforceMobileSDK-Android
- Cordova Plugin: https://github.com/forcedotcom/SalesforceMobileSDK-CordovaPlugin
- Templates: https://github.com/forcedotcom/SalesforceMobileSDK-Templates
- Issues: GitHub Issues
- Questions: Salesforce Stack Exchange
- Community: Trailblazer Community
We welcome contributions! Please:
- Read the CLAUDE.md file for development guidelines
- Follow existing JavaScript code style
- Write or update tests for new functionality
- Test on both iOS and Android platforms
- Submit a pull request with a clear description
Salesforce Mobile SDK License. See LICENSE file for details.