updateSyncTimestamp method

void updateSyncTimestamp({
  1. int? timestampOverride,
})

Updates sync_updated_at field if it exists on this object. Must be called within a write transaction.

Usage:

realm.write(() {
  goal.title = "Updated";
  goal.updateSyncTimestamp();
});

Or with a specific timestamp:

realm.write(() {
  goal.title = "Updated";
  goal.updateSyncTimestamp(timestampOverride: customTimestamp);
});

Implementation

void updateSyncTimestamp({int? timestampOverride}) {
  if (!realm.isInTransaction) {
    throw RealmException(
      'updateSyncTimestamp must be called within a write transaction',
    );
  }

  try {
    // Try to set sync_updated_at using dynamic access
    final timestamp =
        timestampOverride ?? DateTime.now().millisecondsSinceEpoch;
    RealmObjectBase.set(this, 'sync_updated_at', timestamp);
  } catch (e) {
    // Silently ignore if sync_updated_at doesn't exist
    // This allows models without the field to use the extension safely
  }
}