0

So, my Javascript isn't the best but I have to venture into it to run some Cloud Code functions. I have the following:

Parse.Cloud.define("setCommentIsTitle", function(request, response) {
  Parse.Cloud.useMasterKey();

  var query = new Parse.Query("Comment");
  query.equalTo("objectId", request.params.objectId);

  query.first({
      success: function(object) {

          object.set('isTitle', request.params.isTitle);
          return object.save();  },
      error: function(error) {
        alert("Error: " + error.code + " " + error.message);
  }
});

I logged the objectId I'm passing in as request.params.objectId and it's correct. What I don't get is that success is being called, but then I'm getting the following Cloud Code log when I console.log object:

I2013-10-21T17:27:52.120Z] object = undefined

And the following error returned in XCode:

code=141, error=TypeError: Cannot call method 'set' of undefined

If I'm calling the first function on query, and success is being called, shouldn't that mean there is an object returned? Why is object undefined?

1 Answer 1

1

OK, so this was a stupid error on my part, but also abetted by a confusing Parse error message.

My class is called Comments and not Comment, so I was looking up the wrong class. However, since success was called on the query I started looking in all the wrong places for the error.

Why would success be called if I'm querying a class that doesn't even exist??

Sign up to request clarification or add additional context in comments.

Comments

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.