Class: Restforce::SObject
- Defined in:
- lib/restforce/sobject.rb
Instance Method Summary collapse
-
#describe ⇒ Object
Public: Get the describe for this sobject type.
-
#destroy ⇒ Object
Public: Destroy this record.
-
#save ⇒ Object
Public: Persist the attributes to Salesforce.
- #sobject_type ⇒ Object
Methods inherited from Mash
build, #convert_value, #initialize, klass
Constructor Details
This class inherits a constructor from Restforce::Mash
Instance Method Details
#describe ⇒ Object
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 |
#destroy ⇒ Object
Public: Destroy this record.
Examples
account = client.query('select Id, Name from Account').first
account.destroy
34 35 36 37 |
# File 'lib/restforce/sobject.rb', line 34 def destroy ensure_id @client.destroy(sobject_type, self.Id) end |
#save ⇒ Object
Public: Persist the attributes to Salesforce.
Examples
account = client.query('select Id, Name from Account').first
account.Name = 'Foobar'
account.save
20 21 22 23 24 25 26 |
# File 'lib/restforce/sobject.rb', line 20 def save # Remove 'attributes' and parent/child relationships. We only want to # persist the attributes on the sobject. ensure_id attrs = self.to_hash.reject { |key, _| key =~ /.*__r/ || key =~ /^attributes$/ } @client.update(sobject_type, attrs) end |
#sobject_type ⇒ Object
4 5 6 |
# File 'lib/restforce/sobject.rb', line 4 def sobject_type self.attributes.type end |