Set balance value using afterSave trigger

its printing the same address I am trying to sync.
I am now trying to use beforeSave rather than afterSave which gives me only 1 correct value. What I dont know tho is, if beforeSave gets called while data is synced by moralis, or only once in time of existence before the very first save?

If for example tomorrow a transaction happens from a synced wallet, will beforeSave gets called again before data gets updated, or only afterSave?

beforeSave and afterSave will be called both on an update

the problem with beforeSave is that if an error happened in that function then that object is not saved any more

Ok yes thats probably not desireable, did not manage to fix the duplicate entries using afterSave tho

in the working exmample, you had

addressObj.set("value", ethBalance); but didn’t seem that it was defined in that function

True, that was my bad which I noticed afterwards. I replaced that object everywhere with request.object and that still ended up creating 2 objects in the database with 2 different object ids like this

objectId: xy, value: undefined
objectId: yz: value: 0.7

maybe you can run a query, to get the object, and then to update it, in that afterSave

Im gonna try it with the query, although from what I understand the request.object should be the same object one can edit just like its working this way on the beforeSave. Thank you so far for participation