Incremental Syncs with reSync
The following general rules help you decide whether to use syncUp and syncDown, or reSync.
- You can use syncUp or syncDown anytime you want to do a full sync. You can pass in a sync you’ve defined previously, or you can define the sync in the call.
- You can use reSync only to run syncs that are already defined. On the first run, reSync performs a full sync. In subsequent syncs, reSync returns the delta between the last run and the current state.
During sync down, Mobile SDK checks downloaded records for the modification date field specified by the target and remembers the most recent timestamp. If you request a resync for that sync down, Mobile SDK passes the most recent timestamp, if available, to the sync down target. The sync down target then fetches only records created or updated since the given timestamp. The default modification date field is lastModifiedDate.
Of the three built-in sync down targets (MRU, SOSL-based, and SOQL-based), only the SOQL-based sync down target supports reSync. To support reSync in custom sync down targets, use the maxTimeStamp parameter passed during a fetch operation.
Limitation: There Are Ghosts in the Store!
- Records that have been deleted on the server
- Records that no longer satisfy the sync down target
- Run a full sync down operation, or
- Call one of the cleanResyncGhosts methods
Invoking the reSync Method
- iOS:
- On a sync manager instance, call:
- Swift
-
1var syncState = 2 try syncManager.reSync(id: syncState.syncId, onUpdate: updateFunc) - Objective-C
-
1- (nullable SFSyncState*) reSync:(NSNumber*)syncId updateBlock:(SFSyncSyncManagerUpdateBlock)updateBlock;
- Android:
- On a SyncManager instance, call:
- Kotlin
-
1suspend fun suspendReSync(syncId: Long): SyncState - Java
-
1SyncState reSync(long syncId, SyncUpdateCallback callback);
- Hybrid:
- Call:
1cordova.require("com.salesforce.plugin.MobileSync").reSync(syncId,successCB);
Sample Apps
- iOS
- The MobileSyncExplorer sample app uses reSync() in the SObjectDataManager class.
- Android
- The MobileSyncExplorer sample app uses reSync() in the ContactListLoader class.
- Hybrid
- The SimpleSync sample app uses reSync() in SimpleSync.html’s app.views.SearchPage class.