Zack Zhu
Zack Zhu

Reputation: 398

Parse cloud query returns null result

I have the following cloud function

Parse.Cloud.define("test", function(request, response) {
  Parse.Cloud.useMasterKey()
  var query = new Parse.Query("Verification");
  query.equalTo("objectId", "lHBL87Sg2H");

  query.find({
        success: function(results)  
        {
            response.success(results[0].get("objectId"));
        },
        error: function()  
        {
            response.error("failed");
        }
  });
})  

I call this cloud function in Objective C with the following code,

[PFCloud callFunctionInBackground:@"test"
                   withParameters:nil
                            block:^(NSString *result, NSError *error) {
                                if (!error) {
                                    NSLog(@"%@",result);
                                }
                            }];

The result of this call is (null).

The parse log shows the following record

I2015-04-20T20:07:29.383Z] v81: Ran cloud function test1 for user zOpfIOyZQ1 with:
Input: {}
Result: undefined

I also tried the promise but the output is still null.

Upvotes: 1

Views: 484

Answers (1)

danh
danh

Reputation: 62676

To get an object given its id, use Query.get() as follows ...

Parse.Cloud.define("test", function(request, response) {
  Parse.Cloud.useMasterKey();
  var query = new Parse.Query("Verification");
  query.get("lHBL87Sg2H").then(function(object) {
    var objectId = object.id;
    var someAttribute = object.get("foo");
    response.success({"the id is":objectId, "foo is": someAttribute});
  }, function(error) {
    response.error("error " + error.message);
  });
});

Upvotes: 1

Related Questions