I'm looking for a way on how can I check if a phone number exists already in Parse data class in Android.
For example, checking if a phone number exists already, if yes it returns true if not false.
I used this :
query1.whereEqualTo("phone", "0644444444");
query1.findInBackground(new FindCallback<ParseObject>() {
and it doesn't help much.
Use getFirstInBackground() in the query and then simply check to see if there is a ParseException.OBJECT_NOT_FOUND exception. If there is, then the object doesn't exist, otherwise it is there! Using getFirstInBackground is better than findInBackground since getFirstInBackground only checks and returns 1 object, whereas findInBackground may have to query MANY objects.
Example
query1.whereEqualTo("phone", "0644444444");
query1.getFirstInBackground(new GetCallback<ParseObject>() 
{
  public void done(ParseObject object, ParseException e) 
  {
    if(e == null)
    {
     //object exists
    }
    else
    {
      if(e.getCode() == ParseException.OBJECT_NOT_FOUND)
      {
       //object doesn't exist
      }
      else
      {
      //unknown error, debug
      }
     }
  }
});
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With