Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get objectId on Parse.com android

It is said that we can retrieve our data if we are having objectId for that particular row, but it is auto generated and we cant insert it while setting data , so how to get data if i am not having object id , or any other means so that i can set objectId on my means.

Code is here as in comment:

ParseObject gameScore = new ParseObject("My Parse File"); 
String objectId = gameScore.getObjectId(); 
like image 498
Vaishali Sharma Avatar asked Nov 26 '13 09:11

Vaishali Sharma


3 Answers

not sure if this will apply to android , but I was trying to retreive the objectid, but for an entry that is already created. I did something like this and it worked.

ParseObject gameScore = new ParseObject("My Parse File");
var obId = gameScore.id;

Got it from the Javascript docs on Parse.com

The three special values are provided as properties:

var objectId = gameScore.id;

var updatedAt = gameScore.updatedAt;

var createdAt = gameScore.createdAt;
like image 158
Donna Noriega Avatar answered Sep 21 '22 12:09

Donna Noriega


It takes times for your values to be stored in table. Use this to get ObjectId

gameScore.saveInBackground(new SaveCallback() {
    public void done(ParseException e) {
        if (e == null) {
            // Saved successfully.
            Log.d("main", "User update saved!");
            Log.d("main", "ObjectId "+gameScore.getObjectId());

        } else {
            // The save failed.
            Log.d("main", "User update error: " + e);
        }
    }
});
like image 35
Aakash Jindal Avatar answered Sep 21 '22 12:09

Aakash Jindal


ObjectId doesnt't exist until a save operation is completed.

ParseObject gameScore = new ParseObject("My Parse File"); 

To retrieve the object id you need to save the object and register for the save callback.

gameScore.saveInBackground(new SaveCallback <ParseObject>() {
  public void done(ParseException e) {
    if (e == null) {
      // Success!
       String objectId = gameScore.getObjectId();

    } else {
      // Failure!
    }
  }
});

ObjectId can be retrieved from the original ParseObject(gameScore) once the done save callback is fired.

like image 41
Tarun Avatar answered Sep 20 '22 12:09

Tarun