class Restforce::SObject

Public Instance Methods

attrs() click to toggle source

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

# File lib/restforce/sobject.rb, line 54
def attrs
  self.to_hash.reject { |key, _| key =~ /.*__r/ || key =~ /^attributes$/ }
end
describe() click to toggle source

Public: Get the describe for this sobject type

# File lib/restforce/sobject.rb, line 10
def describe
  @client.describe(sobject_type)
end
describe_layouts(layout_id = nil) click to toggle source

Public: Describe layouts for this sobject type

# File lib/restforce/sobject.rb, line 15
def describe_layouts(layout_id = nil)
  @client.describe_layouts(sobject_type, layout_id)
end
destroy() click to toggle source

Public: Destroy this record.

Examples

account = client.query('select Id, Name from Account').first
account.destroy
# File lib/restforce/sobject.rb, line 42
def destroy
  ensure_id
  @client.destroy(sobject_type, self.Id)
end
destroy!() click to toggle source
# File lib/restforce/sobject.rb, line 47
def destroy!
  ensure_id
  @client.destroy!(sobject_type, self.Id)
end
save() click to toggle source

Public: Persist the attributes to Salesforce.

Examples

account = client.query('select Id, Name from Account').first
account.Name = 'Foobar'
account.save
# File lib/restforce/sobject.rb, line 26
def save
  ensure_id
  @client.update(sobject_type, attrs)
end
save!() click to toggle source
# File lib/restforce/sobject.rb, line 31
def save!
  ensure_id
  @client.update!(sobject_type, attrs)
end
sobject_type() click to toggle source
# File lib/restforce/sobject.rb, line 5
def sobject_type
  self.attributes['type']
end
to_sparam() click to toggle source
# File lib/restforce/sobject.rb, line 58
def to_sparam
  self.Id
end

Private Instance Methods

ensure_id() click to toggle source
# File lib/restforce/sobject.rb, line 64
def ensure_id
  return true if self.Id?

  raise ArgumentError, 'You need to query the Id for the record first.'
end