2

I'd like to check if a Cloud Code query response is null or empty. If the query find something, the code works. When there are no objects matching the query, I cannot handle it. What should I do?

Parse.Cloud.define("testing", function(request, response) {


var queryCheckRepeatedPost = new Parse.Query("Update");

queryCheckRepeatedPost.equalTo("updateValid", true); 
queryCheckRepeatedPost.first({
  useMasterKey: true,
    success: function(repeatedPost) {

    //Sometimes query return an object
    //Sometimes there are no objects to return

    },
    error: function() {
        response.error("Error 01");
    }
});

});

I tried:

Object.keys(repeatedPost).length === 0

var value = results[0].get("objectId");

 if (value == null){
 }

But none of them works.

1 Answers1

2

I found the answer. When query returns an empty object it's undefined.

if (repeatedPost != undefined){

   //The object is not empty

}else{
  //the object is empty
}