Skip to content Skip to sidebar Skip to footer

How To Delete Rather Than Duplicate In Parse Object?

I am trying to delete a Row (an Object) from the Parse cloud. Instead of deleting it duplicates the object. I am trying to delete the selectedPost from my parse cloud/database. I a

Solution 1:

To delete try retrieving the item based on a criteria and delete it. I would add a ObjectID attribute to Post and retrieve that and delete it.

So in ownPost() do this

newPost.setObjectID(object.getObjectId());

After you set the objectID for a post then you want to find that object again in Parse after you longclick. So when you click delete, you want to get the object and then delete it.

     builder.setNeutralButton("DELETE POST", newDialogInterface.OnClickListener() {
    publicvoidonClick(DialogInterface dialog, int id) {
        try {
            ParseQuery<ParseObject> query = ParseQuery.getQuery("Post");

            query.whereEqualTo("ObjectID", selectedPost.getObjectId());

            query.findInBackground(newFindCallback<ParseObject>() {
                publicvoiddone(List<ParseObject> postList, ParseException e) {
                    if (e == null) {
                        for (ParseObject post : postList) {
                            post.deleteInBackground();
                        }
                    }
                }
            });
        } catch (ParseException e) {
            e.printStackTrace();
            Log.e("post", "error " + e);
        }
        dialog.dismiss();
    }
});

Solution 2:

You don't need to call saveInBackground() after deleting a ParseObject. Just call deleteInBackground() and it should do the job.

Post a Comment for "How To Delete Rather Than Duplicate In Parse Object?"