parse-platformparse-cloud-codeafter-save

how to get the parse user from the afterSave function


How do I get the parse user in the afterSave function ?

Parse.Cloud.afterSave(Parse.User, function(request) {
    Parse.Cloud.useMasterKey();


    console.log("username: "+request.user.username);


    query = new Parse.Query(Parse.User);
    query.equalTo("username", request.user.username);
    query.first ( {
        success: function(object) {

            //object.relation("users").add(request.user);
            //object.save();
            console.log("sucesss"+ object);

        },
        error: function(error) {
            throw "Got an error " + error.code + " : " + error.message;
        }
    });

});

Solution

  • To get user object that is saved, use request.object. To get the user object that made the change to User class, use request.user. In your case, use the first one.

    Reference: http://www.parse.com/docs/js/api/classes/Parse.Cloud.AfterSaveRequest.html