1
votes

I'm on day 3 of learning Cloud Code and have made minimal progress. I'm confused as to how the call process works. In Cloud Code, I need to use afterSave to query for a class, where key "sent" equals false, and for each recipient in recipients array, push a notification to each and set "sent" to true.

I have the afterSave function saved in main.js, but every time I call it using PFCloud.callFunctionInBackground() I'm getting [Error]: function not found (Code: 141, Version: 1.7.2).

Here's my afterSave trigger:

Parse.Cloud.afterSave("Send", function(request) {
  query = new Parse.Query("Shares");
  query.get(request.object.get("share").id, {
    success: function(post) {
      console.success("Howdy");
    },
    error: function(error) {
      console.error("Got an error " + error.code + " : " + error.message);
    }
  });
});

And here I'm calling the function in Swift:

PFCloud.callFunctionInBackground("Send", withParameters: nil) {
            (response: AnyObject?, error: NSError?) -> Void in
            let result = response as? String
            println(result)

        }

If I'm calling the afterSave trigger inside a saveInBackgroundWithBlock closure, do I call it using PFCloud.callFunctionInBackground?

1

1 Answers

1
votes

I think afterSave is doing something different from what you think it is - it gets triggered automatically when you save an object. In this case, if you had an object of type Send, and you updated that object and saved it, your afterSave function would be called. This is often useful for verifying a saved object is valid, or updating a related object, for example.

I feel like you can accomplish what you're trying to do with a Cloud Function. You can call it from your Swift code, and it's a distinct named function, rather than being a function that is automatically called.