Class: Restforce::DB::Instances::Salesforce

Inherits:
Base
  • Object
show all
Defined in:
lib/restforce/db/instances/salesforce.rb

Overview

Restforce::DB::Instances::Salesforce serves as a wrapper for Salesforce objects, exposing a common API to reconcile record attributes with ActiveRecord instances.

Constant Summary collapse

INTERNAL_ATTRIBUTES =
%w(
  Id
  SynchronizationId__c
  SystemModstamp
  LastModifiedById
).freeze

Instance Attribute Summary

Attributes inherited from Base

#mapping, #record, #record_type

Instance Method Summary collapse

Methods inherited from Base

#after_sync, #attributes, #initialize

Constructor Details

This class inherits a constructor from Restforce::DB::Instances::Base

Instance Method Details

#idObject

Public: Get a common identifier for this record.

Returns a String.



22
23
24
# File 'lib/restforce/db/instances/salesforce.rb', line 22

def id
  @record.Id
end

#last_updateObject

Public: Get the time of the last update to this record.

Returns a Time-compatible object.



39
40
41
# File 'lib/restforce/db/instances/salesforce.rb', line 39

def last_update
  Time.parse(@record.SystemModstamp)
end

#synced?Boolean

Public: Has this record been synced with Salesforce?

Returns a Boolean.

Returns:

  • (Boolean)


46
47
48
# File 'lib/restforce/db/instances/salesforce.rb', line 46

def synced?
  @mapping.database_model.exists?(@mapping.lookup_column => id)
end

#update!(attributes) ⇒ Object

Public: Update the instance with the passed attributes.

attributes - A Hash mapping attribute names to values.

Returns self. Raises if the update fails for any reason.



32
33
34
# File 'lib/restforce/db/instances/salesforce.rb', line 32

def update!(attributes)
  super FieldProcessor.new.process(@record_type, attributes, :update)
end

#updated_internally?Boolean

Public: Was this record most recently updated by Restforce::DB’s workflow?

Returns a Boolean.

Returns:

  • (Boolean)


54
55
56
# File 'lib/restforce/db/instances/salesforce.rb', line 54

def updated_internally?
  @record.LastModifiedById == DB.user_id
end