user3794585
user3794585

Reputation: 203

Query particular Parse user's information?

I have the objectID of a particular user (who is not the current user) and would like to find his Display Name, which is a custom field that I created.

As per Parse's guide, this code will create a list of users that match some particular attributes.

 ParseQuery<ParseUser> query = ParseUser.getQuery();
 query.whereEqualTo("gender", "female");
 query.findInBackground(new FindCallback<ParseUser>() {
 public void done(List<ParseUser> objects, ParseException e) {
 if (e == null) {
    // The query was successful.
} else {
    // Something went wrong.
  }
 }
});

There's no reason for me to make a list, however, if only one user has that objectID. Any way for me to just get the display name of a particular user?

Upvotes: 2

Views: 925

Answers (1)

Timothy Walters
Timothy Walters

Reputation: 16884

What you want instead is getFirstInBackground(), e.g.:

ParseQuery<ParseUser> query = ParseUser.getQuery();
query.getFirstInBackground(someUserId, new GetCallback<ParseUser>() {
    public void done(ParseUser user, ParseException e) {
        if (e == null) {
            // The query was successful.
            // check if we got a match
            if (user == null) {
                // no matching user!
            } else {
                // great, get the name etc
            }
        } else {
            // Something went wrong.
        }
    }
});

Upvotes: 3

Related Questions