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.casecmp('id').zero? }, nil)
  raise ArgumentError, 'ID field missing from provided attributes' unless id
  attrs_without_id = attrs.reject { |k, v| k.to_s.casecmp("id").zero? }
  api_patch "sobjects/#{sobject}/#{CGI.escape(id)}", attrs_without_id
  true
end