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?.

1 Answer 1

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.
    }
  }
});
Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.