Class: Restforce::SObject

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

Instance Method Summary collapse

Methods inherited from Mash

build, #convert_value, #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.



38
39
40
# File 'lib/restforce/sobject.rb', line 38

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

#describeObject

Public: Get the describe for this sobject type



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

def describe
  @client.describe(sobject_type)
end

#destroyObject

Public: Destroy this record.

Examples

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


31
32
33
34
# File 'lib/restforce/sobject.rb', line 31

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


20
21
22
23
# File 'lib/restforce/sobject.rb', line 20

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

#sobject_typeObject



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

def sobject_type
  self.attributes.type
end