2
votes

In my afterSave on a certain Class in Parse Cloud Code, I'm setting the appropriate ACL and then saving the same object again. I have a Push notification going on in that afterSave method, but doing save() in afterSave I think is causing the notifications to be pushed twice or thrice.

How can I handle this situation? Is there a way to save such that the afterSave is not called again? Thoughts? Help is much appreciated! Thanks!

1

1 Answers

5
votes

Depending on when/how you want to send the PUSH, you might use the existed() method to check for the first time a particular instance of your class is being saved. That's what I do for an alert class that generates PUSH notifications. You can simply do:

if (request.object.existed() === false) { 
    // It's a new object 
} else { 
    // It's an existing object
}