Defining a Custom Sync Up Target

You define custom targets for sync up operations by subclassing your platform’s abstract base class for sync up targets. To use custom targets in hybrid apps, you’re required to implement a custom native target class for each platform you support. The base sync up target classes are:

  • iOS:

    SwiftObjective-C
    SyncUpTargetSFSyncUpTarget
  • Android: SyncUpTarget

These classes sync the requested records but not their related records. To include related records, use the sync target classes described in Syncing Related Records.

A target’s Create On Server and Update On Server methods operate only on the list of fields specified in their argument lists. However, a Salesforce object can require the target to create certain fields that can’t be updated by apps. With these objects, a target that uses a single field list for both create and update operations can fail if it tries to update locked fields.

To specify distinct field lists for create and update operations, you can use an initializer method that supports createFieldlist and updateFieldlist parameters. This option can save you the effort of defining a custom target if you’re doing so only to provide these field lists.

Call the following SFSyncUpTarget init method:

Swift

Here's an example:

Objective-C

If you provide the createFieldlist and updateFieldlist arguments, the target uses them where applicable. In those cases, the target ignores the field list defined in the sync options object.

Use the following SyncUpTarget constructor:

If you provide the createFieldlist and updateFieldlist arguments, the target uses them where applicable. In those cases, the target ignores the field list defined in the SyncOptions object.

Every custom target class must implement the following required methods.

Sync up a locally created record. Hybrid and React native apps can override the fields parameter by calling syncUp with the optional createFieldList parameter.

Swift

Objective-C

Sync up a locally updated record. For the objectId parameter, Mobile Sync uses the field specified in the getIdFieldName() method (Android) or the idFieldName property (iOS) of the custom target. Hybrid and React native apps can override the fields parameter by calling syncUp with the optional updateFieldList parameter.

Swift

Objective-C

Sync up a locally deleted record. For the objectId parameter, Mobile Sync uses the field specified in the getIdFieldName() method (Android) or the idFieldName property (iOS) of the custom target.

Swift

Objective-C

Android:

Optionally, you can override the following values in your custom class.

List of record IDs returned for syncing up. By default, these methods return any record where __local__ is true.

Swift

Objective-C

Android:

Field used during a LEAVE_IF_CHANGED sync up operation to determine whether a record was remotely modified. Default value is lastModifiedDate.

iOS (Swift and Objective-C):

modificationDateFieldName property

Android:

Determines whether a soup element is more current than the corresponding server record.

Swift

Objective-C

Android:

Field used to get the ID of the record. For example, during sync up, Mobile SDK obtains the ID that it passes to the updateOnServer() method from the field whose name matches idFieldName in the local record.

iOS (Swift and Objective-C):

idFieldName property

Android:

String getIdFieldName();