Salesforce Mobile SDK and Ionic – Offline – SmartStore Query by Exact

Sometimes when getting data from the Soup we will need to be able to get one specific record, or a group of records that match a certain criteria.  SmartStore allows us to do this using the Query by Exact feature and the buildExactQuerySpec function.  Using buildExactQuerySpec we will be able to tailor our query similar to the where clause of a SQL/SOQL statement.


Since we already know how to make a querySpec so let’s look at how buildExactQuerySpec is different from buildAllQuerySpec.  buildExactQuerySpec takes path, matchKey, pageSize, order, orderPath, selectPaths and since pageSize, order, selectPaths are the same as buildAllQuerySpec let’s focus on the other 3.


What you looking for, similar to indexPath with buildAllQuerySpec.


The string to match against the path.


Used to specify the path to order the search by.

So to query by Id we could specify the 'Id' as the path and pass in an Id that we have in our soup.  After building the querySpec the rest of calling querySoup remains the same.

Query by Id

exactQuery(): Promise<any> {

  let id = '003j0000008CVYlAAO';  //id from soup

  let promise = new Promise((resolve, reject) => {

    var querySpec = (navigator as sdkNavigator).smartstore.buildExactQuerySpec('Id', id);

    let success = (results) => {

    (navigator as sdkNavigator).smartstore.querySoup(this.soupName, querySpec, success, reject);

    promise.then(results => {


Here you can see we still use a success callback and a failure callback along with using the soup name.


Don’t forget to sign up for The Weekly Stand-Up! to receive free the WIP weekly newsletter every Sunday!

Leave a Reply