How to get objectId on parse.com android

They say that we can get our data if we have an objectId for this particular row, but it is automatically generated, and we can’t insert it when setting up the data, so how to get the data if I don’t have an object identifier, or any other means so that I can set objectId to my means.

The code is here, as in the comment:

ParseObject gameScore = new ParseObject("My Parse File"); String objectId = gameScore.getObjectId(); 
+7
android
source share
6 answers

ObjectId does not exist until the save operation completes.

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

To get the identifier of an object, you need to save the object and register it for a 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) after running the completed callback.

+7
source share

You can use this to get the current user object id

 ParseUser pUser= ParseUser.getCurrentUser(); String objId= pUser.getObjectId(); 
+2
source share

Not sure if this applies to android, but I tried to return an object-object, but for a record that was 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
source share

You cannot, unfortunately, use ObjectId until the object is saved. Now I have the same problem. The only solution I can think of, and posted a similar question related to it here

My solution was to make the tempId object on the object and reference it locally until it has the actual ObjectId object, perhaps using the saveInBackground or saveEventually() to set other objects associated with it, created an ObjectId instead of the old temp one .. when it became available

+1
source share

If you process the stream yourself:

First save:

 gameScore.save(); 

Then you can access id:

 String parseId = gameScore.getObjectId(); 
0
source share

It takes time to save the values ​​in the table. Use this to get an 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); } } }); 
0
source share

All Articles