NSMSTR
NSMSTR

Reputation: 1

Parse.Query get() fails to retrieve object

I am unable to retrieve a PFUser object using its objectId. I always get an "Object not found" error.

I do not understand why this is happening. When I log userObjectUniqueID to the console I can see that it's the exact objectId for the PFUser I'm trying to retrieve. From what I understand from the documentation, this should give me object that belongs to the objectId.

Parse.Cloud.define("myFunction", function(request, response){
    var userObjectUniqueID = request.params.userUniqueID; //Unique object ID for the user object.

    var UserClass = Parse.Object.extend("User"); //Referencing the user class.
    var userQuery = new Parse.Query(UserClass);

    userQuery.get(userObjectUniqueID, {
        success: function(user){
            alert("Query was successful.")
        },
        error: function(object, error)
        {
            alert("query failed: " + error.message);
        }
    })

});

I've also tried to use the find() function in Parse.Query to retrieve the PFUser object. Even though I've used the appropriate constraints, it still won't return the object.

Any ideas?

Upvotes: 0

Views: 1216

Answers (1)

Timothy Walters
Timothy Walters

Reputation: 16874

You've made a common mistake, in that the internal classes "User", "Role" and "Installation" have special names (prefixed with an underscore).

The preferred way to do it is:

var userQuery = new Parse.Query(Parse.User);

You can also use "_User" as the class name if you need to extend, though the above is preferred.

Upvotes: 1

Related Questions