module Restforce::Concerns::API

def update!(sobject, attrs)

Raises an exception if an error is returned from Salesforce.
Returns true if the sobject was successfully updated.

client.update!('Account', Id: '0016000000MRatd', Name: 'Whizbang Corp')
# Update the Account with Id '0016000000MRatd'

Examples

attrs - Hash of attributes to set on the record.
sobject - String name of the sobject.

Public: Update a record.
def update!(sobject, attrs)
  id = attrs.fetch(attrs.keys.find { |k, v| k.to_s.downcase == 'id' }, nil)
  raise ArgumentError, 'Id field missing from attrs.' unless id
  attrs_without_id = attrs.reject { |k, v| k.to_s.downcase == "id" }
  api_patch "sobjects/#{sobject}/#{id}", attrs_without_id
  true
end