Handling “Ghost” Records After Sync Down Operations

If you’re finding that sync down operations sometimes leave unwanted records in your SmartStore soups, you can use the cleanResyncGhosts API to get rid of them.

In certain prescribed cases, SmartStore soups do not reflect the exact contents of the most recent sync down request. For example, if a record is deleted on the Salesforce server, the next sync down operation doesn’t remove that record from SmartStore. Also, records that don’t satisfy the sync criteria are excluded from the sync down results but aren’t automatically removed from the soup. These records that unexpectedly remain in the SmartStore soup are known as ghosts.

To root out these haunts, Mobile Sync provides a set of cleanResyncGhosts methods that identify and remove ghosts. You pass in the ID or name of a sync object and define a callback block. These methods are available for Android native, iOS native, hybrid, and React Native platforms.

Exercise restraint in using the cleanResyncGhosts methods! Calls to these methods can be expensive in both runtime performance and payload size. Use these methods for low-frequency cleanup, rather than as part of every sync down operation. Use your own judgment to determine whether a particular set of ghosts is problematic and therefore requires immediate cleanup.

If your app uses a custom sync down target, cleanResyncGhosts requires the custom target to implement the getListOfRemoteIds method. This method returns the list of Salesforce IDs that satisfy the sync down target’s criteria. For getListOfRemoteIds coding examples, see the SOQL, SOSL, or MRU sync down target in these Mobile Sync library folders:





For the target soup, add an index for the following field:


This field ensures that the cleanResyncGhosts() method removes only the desired soup elements. Mobile Sync manages the content of this field for you.


In Mobile SDK 7.1, the following method is updated to throw.


In Mobile SDK 7.1, the following method is updated to support an NSError output parameter.




React Native

You can also call cleanResyncGhosts with a sync name.

iOS (Swift)

iOS (Objective-C)

Android (Kotlin)

Android (Java)

Deprecated iOS Method (Objective-C)

The following method that does not support an NSError output parameter is slated for removal in a future major release.