0

Im trying to run this cloud code every time a new object gets saved to my class called "Message", however i believe i am calling the afterSave method incorrectly because not even my console.log is showing up after i save a new object to my class called "Message". What is wrong with my code?

Parse.Cloud.afterSave("sendMessage", function(Message, response) {
  var messageBody = null;
  var messageSenderName = null;
  var messageSenderId = null;
  var randUsers = [];
  console.log("The variables were set");
 ............other code that doesn't matter................
});
ian
  • 1,002
  • 2
  • 12
  • 29
  • The callback function should only have one argument, (`function(request){...}`) and you can access the message by using `request.object`. Also, are you sure that sendMessage is capitalized correctly? – orhanhenrik Oct 06 '14 at 17:43
  • Is sendMessage not just an arbitrary name that i want to call the function? – ian Oct 06 '14 at 17:54
  • 1
    `sendMessage` is the name of the Class that is being saved. Whenever an object from that table is saved, this `afterSave` will be called. – Dehli Oct 06 '14 at 17:55
  • So it should probably be just Message then huh? – ian Oct 06 '14 at 17:56
  • Yup, in quotes. `"Message"` – Dehli Oct 06 '14 at 18:00

1 Answers1

2

As far as I see, you want to fire up a cloud function whenever new entry is saved to Parse DB. For this scenario afterSave is the way to go. However, your function declaration is wrong. The function must be in the format;

Parse.Cloud.afterSave("Message", function(request) {
.....
}

where the request contains the currently saved entry information.Hope this helps.Regards.

kingspeech
  • 1,776
  • 2
  • 14
  • 24