Class: Restforce::SObject

Inherits:
Mash
  • Object
show all
Defined in:
lib/restforce/sobject.rb

Direct Known Subclasses

Attachment, Document

Instance Method Summary collapse

Methods inherited from Mash

build, #convert_value, #dup, #initialize, klass

Constructor Details

This class inherits a constructor from Restforce::Mash

Instance Method Details

#attrsObject

Public: Returns a hash representation of this object with the attributes key and parent/child relationships removed.



52
53
54
# File 'lib/restforce/sobject.rb', line 52

def attrs
  self.to_hash.reject { |key, _| key =~ /.*__r/ || key =~ /^attributes$/ }
end

#describeObject

Public: Get the describe for this sobject type



8
9
10
# File 'lib/restforce/sobject.rb', line 8

def describe
  @client.describe(sobject_type)
end

#describe_layouts(layout_id = nil) ⇒ Object

Public: Describe layouts for this sobject type



13
14
15
# File 'lib/restforce/sobject.rb', line 13

def describe_layouts(layout_id = nil)
  @client.describe_layouts(sobject_type, layout_id)
end

#destroyObject

Public: Destroy this record.

Examples

 = client.query('select Id, Name from Account').first
.destroy


40
41
42
43
# File 'lib/restforce/sobject.rb', line 40

def destroy
  ensure_id
  @client.destroy(sobject_type, self.Id)
end

#destroy!Object



45
46
47
48
# File 'lib/restforce/sobject.rb', line 45

def destroy!
  ensure_id
  @client.destroy!(sobject_type, self.Id)
end

#saveObject

Public: Persist the attributes to Salesforce.

Examples

 = client.query('select Id, Name from Account').first
.Name = 'Foobar'
.save


24
25
26
27
# File 'lib/restforce/sobject.rb', line 24

def save
  ensure_id
  @client.update(sobject_type, attrs)
end

#save!Object



29
30
31
32
# File 'lib/restforce/sobject.rb', line 29

def save!
  ensure_id
  @client.update!(sobject_type, attrs)
end

#sobject_typeObject



3
4
5
# File 'lib/restforce/sobject.rb', line 3

def sobject_type
  self.attributes['type']
end

#to_sparamObject



56
57
58
# File 'lib/restforce/sobject.rb', line 56

def to_sparam
  self.Id
end