10

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(); 
4
  • Show your effort also which you have tried. Commented Nov 26, 2013 at 9:51
  • check this link: parse.com/questions/… Commented Nov 26, 2013 at 10:17
  • In this link you will find that after save the some data it will return the objectid. Commented Nov 26, 2013 at 10:17
  • Hi there I am also stuck on the same problem as yours stackoverflow.com/q/34854990/5524159 did you find out the solution. Have a look at my question. Please help me Commented Jan 18, 2016 at 13:50

6 Answers 6

8

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.

Sign up to request clarification or add additional context in comments.

5 Comments

This code is creating a new row on server, and returning id of that newly created row. And i want to retrieve id of already created row on the basis of one value.
query.findInBackground(new FindCallback<ParseObject>() { @Override public void done(List<ParseObject> scoreList, com.parse.ParseException e) { if (e == null) { Log.d("score", "Retrieved " + scoreList.size() + " scores"); System.out.println("list is "+scoreList); String obb = gameScore.getObjectId(); // String aa = gameScore.getParseObject("Entry").toString(); System.out.println("aa "+obb); } else { Log.d("score", "Error: " + e.getMessage()); }}
You might be calling save twice. You change your existing save to the one I mentioned in the answer.
Would this not complain about the use of final on gameScore?
@VaishaliSharma I am facing the problem. How can I update my previously created score because each time ParseObject gameScore = new ParseObject("User"); creating a new row. I want to update previous row. Thanks
2

You can use this for getting current user object id

ParseUser pUser= ParseUser.getCurrentUser();
String objId= pUser.getObjectId();

Comments

2

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;

1 Comment

In my current app, .id appears to be the correct way to get this (as of 1/23/2021).
1

You can't unfortunately use the ObjectId until the object's been saved. I'm having this same problem now. The only solution I can think of, and posted a similar question relating to it here

My solution would be to make a tempId on the object and refer to that locally until it has an actual ObjectId, perhaps using a saveInBackground or saveEventually() callback to set other objects relating to it, to it's newly created ObjectId instead of it's old temp one.. when it's made available

Comments

1

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);
        }
    }
});

Comments

0

In case you're handling the thread yourself:

First save:

gameScore.save();

Then you'll be able to access the id:

String parseId = gameScore.getObjectId();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.