Using Global SmartStore

Although you usually tie a SmartStore instance to a specific customer’s credentials, you can also access a global instance for special requirements.

Under certain circumstances, some applications require access to a SmartStore instance that is not tied to Salesforce authentication. This situation can occur in apps that store application state or other data that does not depend on a Salesforce user, organization, or community. To address this situation, Mobile SDK supports global stores that persists beyond the app’s life cycle.

Data stored in global stores does not depend on user authentication and therefore is not deleted at logout. Since a global store remains intact after logout, you are responsible for deleting its data when the app exits. Mobile SDK provides APIs for this purpose.

Do not store user-specific data in global SmartStore. Doing so violates Mobile SDK security requirements because user data can persist after the user logs out.

Important

Android APIs 

In Android, you access global SmartStore through an instance of SmartStoreSDKManager.

  • Returns a global SmartStore instance with the specified database name. You can set dbName to any string other than “smartstore”. Set dbName to null to use the default global SmartStore database.

    1public  getGlobal(String dbName)
  • Checks if a global SmartStore instance exists with the specified database name. Set dbName to null to verify the existence of the default global SmartStore.

    1public boolean hasGlobal(String dbName)
  • Deletes the specified global SmartStore database. You can set this name to any string other than “smartstore”. Set dbName to null to remove the default global SmartStore.

    1public void removeGlobal(String dbName)

iOS APIs 

In iOS, you access global SmartStore through an instance of SFSmartStore.

  • Returns a global SmartStore instance with the specified database name. You can set storeName to any string other than “defaultStore”. Set storeName to kDefaultSmartStoreName to use the default global SmartStore.

Objective-C:

1+ (id)sharedGlobalStoreWithName:(NSString *)storeName

Swift:

1var gstore = SmartStore.sharedGlobal(withName: storeName)
  • Deletes the specified global SmartStore database. You can set storeName to any string other than “defaultStore”. Set storeName to kDefaultSmartStoreName to use the default global SmartStore.

Objective-C:

1+ (void)removeSharedGlobalStoreWithName:(NSString *)storeName

Swift:

1SmartStore.removeSharedGlobal(withName: storeName)

Hybrid APIs 

Most SmartStore JavaScript soup methods take an optional first argument that specifies whether to use global SmartStore. This argument can be a Boolean value or a StoreConfig object. If this argument is absent, Mobile SDK uses the default user store.

For example:

1querySoup([isGlobalStore, ]soupName, querySpec,
2    successCB, errorCB);
3querySoup([storeConfig, ]soupName, querySpec,
4    successCB, errorCB);

SmartStore defines the following functions for removing stores. Each function takes success and error callbacks. The removeStore() function also requires either a StoreConfig object that specifies the store name, or just the store name as a string.

1removeStore(storeConfig, successCB, errorCB);
2removeAllGlobalStores(successCB, errorCB);
3removeAllStores(successCB, errorCB);

See Also 

We've Moved

Welcome to the new home of the Mobile SDK Developer Guide! For now, the Japanese guide can be found in PDF form.