Retrieving user using Backendless.findById

Hello,

I’m trying to get the name of another user using the following code, but I am getting the error “Entity with ID ___ not found”.

Slightly irrelevant but might help: In the property “friends”, I am storing the friends list of each user as a JSON. The code in handleResponse is me adding each user to the other’s friends list.

Backendless.UserService.findById(searchUser, new AsyncCallback<BackendlessUser>() {
@Override
public void handleResponse(BackendlessUser response) {
String newFriend=response.getProperty(“username”).toString();
String user1Name=currentUser.getProperty(“username”).toString();
ArrayList<String> user2Friends=new ArrayList<String>();
JsonParser parser = new JsonParser();
JsonArray user2JSONArray= parser.parse(newFriend).getAsJsonArray();
for(JsonElement user2JsonElement: user2JSONArray){
JsonObject json= user2JsonElement.getAsJsonObject();
String user2Friend=json.get(“friend”).getAsString();
user2Friends.add(user2Friend);
}
user2Friends.add(user1Name);
JsonArray uploadUser2Friends= new JsonArray();
for(String friend: user2Friends){
JsonObject user2FriendJSON=new JsonObject();
user2FriendJSON.addProperty(“friends”, friend);
uploadUser2Friends.add(user2FriendJSON);
}
String user2UploadFriendsString= uploadUser2Friends.toString();
response.setProperty(“friends”,user2UploadFriendsString);
friends.add(newFriend);
}

@Override
public void handleFault(BackendlessFault fault) {
    Toast.makeText(getApplicationContext(), fault.getMessage(), Toast.LENGTH_SHORT).show();
}

});

The argument of the findById method must be the value of the “objectId” property. Since your argument does not contain a valid objectId, you’re getting that error.

Regards,
Mark

“username” is the property I’m using as the user identifier. I am getting searchName as a String from an EditText (which I am using to search for the required user).

How do I retrieve the user using the string containing the username to be searched for?

Thanks,
Rajas

use a data retrieval with a whereClause instead:
https://backendless.com/docs/android/doc.html#data_search_with_where_clause

This worked! Thank you so much!