0

Hello i am having some trouble in a Query. I made a pointer called "Empresa" in the _User class. i understand that this pointer is a ParseObject.So i did this i tried to do it in two ways...

private void queryEmpresa(){
    ParseQuery<ParseObject> query = ParseQuery.getQuery("_User");
    query.whereEqualTo("objectId", ParseUser.getCurrentUser().getObjectId);
    query.include("Empresa");
    query.findInBackground(new FindCallback<ParseObject>() {
        @Override
        public void done(List<ParseObject> objects, ParseException e) {
            for (ParseObject obj:objects
                 ) {

                empresa=obj.getParseObject("Empresa");
                String id=empresa.getObjectId();

            }

        }
    });
}

and also...

 private void queryEmpresa(){
    ParseQuery<ParseUser> query = ParseUser.getQuery();
    query.whereEqualTo("objectId", ParseUser.getCurrentUser().getObjectId());
    query.include("Empresa");
    query.findInBackground(new FindCallback<ParseUser>() {
        @Override
        public void done(List<ParseUser> objects, ParseException e) {
            for (ParseUser obj:objects
                 ) {
                empresa=obj.getParseObject("Empresa");
                String id=empresa.getObjectId();
            }

        }
    });


}

tell me which is the correct code and what do i need to modify in order to work. Can you please explain to me why is the reason this isnt working so that i dont incur into this problem in the near future?.

Felipe Franco
  • 171
  • 3
  • 15

1 Answers1

2

Try this and check if you get some error from the server:

ParseQuery<ParseUser> query = ParseUser.getQuery();
query.include("Empresa");
query.getInBackground(ParseUser.getCurrentUser().getObjectId(), new GetCallback<ParseObject>() {
  public void done(ParseObject object, ParseException e) {
    if (e == null) {
      // object will be your user and you should be able to retrieve Empresa like this
      empresa = object.getParseObject("Empresa");
    } else {
      // something went wrong. It would be good to log.
    }
  }
});
Davi Macêdo
  • 2,954
  • 1
  • 8
  • 11
  • 1
    It should work. Can you please update the code so I can check what is wrong? Please, also send the full error message you have. – Davi Macêdo May 28 '19 at 17:10