Possible to get previous value of object in Parse Cloud Code AfterSave?

I have an AfterSave function that updates something else based on the previous value of the object that was just saved. Simply knowing that the object has changed with object.existed() is not enough.

Is there any way to get the previous value of an object's property without implementing a costly workaround and increasing the number of API calls?

Is it even possible to get the previous value of an object in the AfterSave function?

When I call object.previous("value"), I get an undefined value.



Don't know if this is helpful or if it would be considered too costly of a workaround, but you could add a column to the object that is being updated that stores the previous value of the original column. This would allow you to access the previous value in the AfterSave function.


Unfortunately I don't have reputation to comment on dstefanis' approach.

This approach is good when one endpoint is changing the value - and indeed I've used it before to this end.

There's a critical limitation in that if multiple endpoints are writing, they may still keep over-writing both the "current" and "old" fields. This means it can't be used to give any strict assurances - e.g. "this field will never be decremented".

A conflict-safe way is to do a parse query by objectId, and pick up the old value. You can then do your own conflict resolution. I have this tested and working :-)


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.