Query to Users Table

Hi friends,

  • I want to retreive Users Table object from other Project and this is what I’m doing
    Backendless.initApp(context,APPLICATION_ID_OTHER_PROJECT,.ANDROID_SECRET_KEY_OTHER_PROJECT);
    Backendless.Data.of(BackendlessUser.class).findById(“objectId_fromOtherUserProject”, new AsyncCallback<BackendlessUser>() {
    @Override
    public void handleResponse(BackendlessUser response) {
    BackendlessUser otherUser=response;
    }

@Override
public void handleFault(BackendlessFault fault) {

}
});
At the end my otherUser variable is null.
First of all I’m not sure if that’s the proper way to get data from other project and UsersTable object.
Please your help.
Thanks a lot!!

Hi Nathan,

Where in your code do you check the value of otherUser? Note that the request is asynchronous and the otherUser variable will not be initialized immediately after you call findById.

Hi Sergey , thanks for the response, but I check otherUser variable after find method, but it still null.
The following is the scenario I have issues:
helperBackend is empty after call Backendless.Data.of(BackendlessUser.class)…
‘response’ is a list of objects that have email property that are the same emails from the table Users which I want to retrieve data.

List<BackendlessUser> helperBackend = BackendlessHelperUtils.findHelpersFromBackend(getApplicationContext(), response);

public class BackendlessHelperUtils {

public static List<BackendlessUser> findHelpersFromBackend(Context context, List<Helper> list) {
Backendless.initApp(context, BackendlessSettings.APPLICATION_ID_HELPERS, BackendlessSettings.ANDROID_SECRET_KEY_HELPERS);
final List<BackendlessUser> auxListaHelper = new ArrayList<>();

for (Helper helper : list) {
StringBuilder whereClause = new StringBuilder();
whereClause.append(“email”);
whereClause.append("=’").append(helper.getEmail()).append("’");
DataQueryBuilder dataQueryBuilder=DataQueryBuilder.create();
dataQueryBuilder.setWhereClause(whereClause.toString());
Backendless.Persistence.of(BackendlessUser.class).find(dataQueryBuilder, new AsyncCallback<List<BackendlessUser>>() {
@Override
public void handleResponse(List<BackendlessUser> response) {
if (response!=null && response.size()>0){
auxListaHelper.add(response.get(0));
}
}
@Override
public void handleFault(BackendlessFault fault) {

}
});
}
return auxListaHelper;
}
}

I can’t understand why that happen, I’m using ‘com.backendless:backendless:5.1.0’ as dependency.

Please you help.
Thanks a lot.

From what I see in your code, you’re effectively returning an empty auxListaHelper list from the method, because the find call is asynchronous and most probably it hadn’t enough time to fill up the list with the response.