Izel Maras
Izel Maras

Reputation: 1

Updating a ParseUser field

I am trying to update a field in a ParseUser and I am using an external library to use Parse with Java. Even though I get the ParseUser object and can use functions like getEmail(), getUsername(), the functions like setEmail("[email protected]"), put("friends", list), setUsername("bom") doesn't work.

Any ideas on how to solve this?

void updateParse(int id){
  ParseQuery<ParseUser> query = ParseQuery.getQuery(ParseUser.class);
  query.whereEqualTo("alikeId", 2);
  query.findInBackground(new FindCallback<ParseUser>() {
    public void done(List<ParseUser> results, parse4p.ParseException e) {
      if ( results == null) {
        println("Name not found within the class");
      } else {
        ParseUser temp = results.get(0);
        temp.setEmail("[email protected]");

          }
        }
      }
      );    

}

Upvotes: 0

Views: 414

Answers (2)

JayDev
JayDev

Reputation: 1360

The first problem with your code is that even though you set the email, you never actually run temp.saveInBackground(), so the parse database won't be updated.

More importantly, Parse has default security on its User class, that only allows you to edit the values for the currently logged in user. So even if you were to use temp.saveInBackground() in your current context, it wouldn't work as the security for the User class wouldn't allow it.

Upvotes: 2

bjiang
bjiang

Reputation: 6078

You can try following sample code to update the parseUser:

ParseUser user = ParseUser.getCurrentUser();
user.increment("logins");
user.saveInBackground(new SaveCallback() {
  public void done(ParseException e) {
    if (e != null) {
      // Saved successfully
    } else {
      // ParseException
    }
  }
});

Upvotes: 0

Related Questions