Method: Restforce::DB::Model#force_sync!
- Defined in:
- lib/restforce/db/model.rb
#force_sync! ⇒ Object
Public: Force a synchronization to run for this specific record. If the record has not yet been pushed up to Salesforce, create it. In the event that the record has already been synchronized, force the data to be re- synchronized.
NOTE: To ensure that we aren’t attempting to synchronize data which has not actually been committed to the database, this method no-ops for unpersisted records, and discards all local changes to the record prior to syncing.
Returns a Boolean.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/restforce/db/model.rb', line 45 def force_sync! return false unless persisted? reload sync_instances.each do |instance| salesforce_record_type = instance.mapping.salesforce_record_type if instance.synced? salesforce_instance = salesforce_record_type.find(instance.id) next unless salesforce_instance accumulator = Restforce::DB::Accumulator.new accumulator.store(instance.last_update, instance.attributes) accumulator.store(salesforce_instance.last_update, salesforce_instance.attributes) synchronizer = Restforce::DB::Synchronizer.new(instance.mapping) synchronizer.update(instance, accumulator) synchronizer.update(salesforce_instance, accumulator) else salesforce_record_type.create!(instance) end end true end |