Offline Management App

What is Salesforce SmartStore?

SmartStore is an encrypted NoSQL-style JSON document data store. In fact, it is the only cross-platform encrypted NoSQL mobile database on the market that works with both hybrid and native development models

  1. Salesforce Mobile SDK SmartStore to store encrypted data in a NoSQL-style database on both iOS and Android devices.
  2. The app’s connectivity should be transparent to the user, and switching between online and offline should be seamless.
  3. This allows users to focus on using the app to do their job rather than about with online / offline settings.
  4. The app will first attempt to load records from SmartStore. If none exist, it will check if the device is online. If it is, finally it will attempt to load the records from

The above method is good for reading data from the Salesforce

What if the user needs to be able to Create, Update, or Delete data?

  1. Any time a record is upserted or deleted in the app, the local copy of that record is upserted or deleted and a queue record is created too.
  2. If the app is online, the record can be upserted or deleted in immediately and the queue record can be deleted.
  3. Since the queue record isn’t deleted until a successful response is received from the Salesforce API, this ensures that no data will be lost regardless of whether the device is online, offline, or has a bad connection and a synchronization error occurred during data transfer.
  4. Salesforce can also calculate values for some fields by using formula fields, workflow rules, or triggers. It’s a good practice to query for any recently upserted records just to make sure the data is in sync across Salesforce and the mobile device.
  5. “NoSQL” databases are a class of database that, unlike their “relational” brethren, are designed to be inherently schemaless. They take care of storing data and let the application worry about how to structure it.
  6. Some typical benefits of this style of database is their raw speed, a dynamic schema where fields and tables can be added by the application at will, and easy of use for the developer.
  7. Rest API and Chatter API both return JSON documents from the server.
  8. The code you wrote to process the data you’re getting from the Rest API is the same code you’ll use to process the data you’re getting from SmartStore, and you don’t have to set up a schema offline.


  1. In the typical relational database, data is stored in “tables,”  where data is segmented across many tables in order to avoid things like duplicating data.
  2. With SmartStore, data is stored in “soups,” Soups are then saved in Stores, which are essentially separate database files on a disk.
  3. Unless you have some strong need for multiple database files, most apps will have only one Store and any number of Soups.

Register a Soup

You can register a new soup with an IndexSpec. An IndexSpec is a simple JSON document that tells SmartStore which fields need to be indexed for searching, upserting, deleting, and sorting.

Query a Soup

Let’s query the registered soup with NoSQL database. Four different types of QuerySpec to query

  1. BuildAllQuerySpec = function(path, order, pageSize).
  2. This QuerySpec is used to query all records from the object in the given sorted order (or null order). This is the one to use if you want to load all records from a Soup into app memory and work with it there. This isn’t the best option if you have a lot of data in a soup.
  3. BuildExactQuerySpec = function(path, matchKey, pageSize).
  4. Use this QuerySpec if you know exactly what record you want.
  5. BuildRangeQuerySpec = function(path, beginKey, endKey, order, pageSize).

This QuerySpec is similar to the ExactQuerySpec, but it allows you to specify a range of values with the beginKey and endKey parameters. For instance, if you wanted to query all Names between “Adams” and “Zaphod”, you would want to use this QuerySpec.

  • BuildLikeQuerySpec = function(path, likeKey, order, pageSize)

The query is similar to the LIKE clause and allows you to search for a substring within string indexes

Upsert data

You just need to specify which soup you want to write to and pass in a JSON document for the entries parameter. It will be automatically indexed using the indexes you specified when you registered the soup earlier.

UpsertSoupEntries = function (soupName, entries, successCB, errorCB)

Delete Data

No database would be complete without some way to delete data, and SmartStore provides the RemoveFromSoup method for just that reason.

RemoveFromSoup = function (soupName, entryIds, successCB, errorCB)

Scroll to Top