4

I have a case when SF data can be updated concurrently by humans with UI and by a Ruby app via REST API, so I'm worried about the possibility they overwrite changes of each other.

Is there a standard way to conditionally make an update only if the object hasn't been changed in the meanwhile?(check the version of object, or last update time, etc).

Or is it possible to achieve this with a SOQL query similar to this?
update stuff set calculated_field = 'new value' where base_field = 'expected old value'

3

If the Ruby script updates a record between the time the user loads the edit page and clicks Save, they'll get a "record has been modified" error to prevent them from overwriting data.

If the user updates a record between the time the Ruby script queries the record and chooses to update the record, that data may be overwritten unless the Ruby script provides the If-Unmodified-Since header. As a practical matter, you should always use the If-Unmodified-Since header to avoid overwriting data from other sources.

You can also use the If-Match header if you cached the ETag header, which is a hash that defines the state of the record at the time of retrieval. You can also use this to prevent unintentional overwrites to the data by providing the expected hash value.

You can read more about that header, and more, in the Using Conditional Requests documentation.

  • Thank you, just what I needed. I'll experiment with it and accept your answer. – RocketR Dec 12 '17 at 9:23
  • So it seems I cannot use the ETag and If-Match/If-None-Match, because, as the linked page states, it's supported for account records only. – RocketR Dec 12 '17 at 12:16
  • If-Unmodified-Since header does the trick. The GET response contains a Date header, which you can then pass as If-Unmodified-Since when making a PATCH request. – RocketR Dec 12 '17 at 12:28
  • @RocketR Ah, thanks for pointing that out. I must have missed the parenthetical statement. I'm glad I was able to help you out! – sfdcfox Dec 12 '17 at 14:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.