3

Is the aftersave function in the cloud code called every-time an object of a specific class is updated or is it called only after an object of the class is created ?

1 Answers1

7

The afterSave cloud function is called every time an object of that class is created or updated. (persisted) in the database.

However, if you want it to tigger only when the object is created, you should do as follow:

Parse.Cloud.afterSave('your_class_name', (request) => {

  if (!request.original) {
    // this means the object is just created

  } else {
    // this means it is an update to the object.


  }
});
imana97
  • 400
  • 2
  • 10
  • Where are these things documented? How can I learn more about those? Parse Server documentation have not these. – Sangam May 23 '21 at 13:49
  • I'm not sure if this is documented, but this appears to be true based on these lines in the source code: https://github.com/parse-community/parse-server/blob/4c29d4d23b67e4abaf25803fe71cae47ce1b5957/src/triggers.js#L276 – Layne Bernardo Mar 02 '22 at 00:18