Method: Restforce::Client::API#upsert!
- Defined in:
- lib/restforce/client/api.rb
#upsert!(sobject, field, attrs) ⇒ Object
Public: Update or create a record based on an external ID
sobject - The name of the sobject to created. field - The name of the external Id field to match against. attrs - Hash of attributes for the record.
Examples
# Update the record with external ID of 12
client.upsert!('Account', 'External__c', External__c: 12, Name: 'Foobar')
Returns true if the record was found and updated. Returns the Id of the newly created record if the record was created. Raises an exception if an error is returned from Salesforce.
226 227 228 229 230 |
# File 'lib/restforce/client/api.rb', line 226 def upsert!(sobject, field, attrs) external_id = attrs.delete(attrs.keys.find { |k| k.to_s.downcase == field.to_s.downcase }) response = api_patch "sobjects/#{sobject}/#{field.to_s}/#{external_id}", attrs (response.body && response.body['id']) ? response.body['id'] : true end |