2

I am making a social app using Objective-C and Parse. I am trying to write cloud code to increment likes (which is part of the secured User class) upon a button click. This is what I have as of now:

Cloud Code

Parse.Cloud.define("incrementLikes", function(request, response) {
               Parse.Cloud.useMasterKey();
               var user = new Parse.Object("User");
               user.userName = request.params.userName;
               user.increment("profilePictureLikes");
});

profilePictureLikes is the name of the database row within the User class that is a number.

Objective-C

- (void)incrementLikes {
    [PFCloud callFunctionInBackground:@"incrementLikes" withParameters:@{@"userName": self.user.username}];
}

self.user is the PFUser whose profile is being viewed.

This code generates the following error, and does not increment the likes:

[Error]: success/error was not called (Code: 141, Version: 1.6.2)
Artem Sapegin
  • 3,096
  • 2
  • 16
  • 20
user3784214
  • 105
  • 9

1 Answers1

2

Well, the error is because you aren't calling the response handler in the cloud code but you have a number of other issues:

  1. Not calling the response handler
  2. Creating a new user instead of querying to find the existing user
  3. Passing the user name instead of the user object id (see here)
  4. Not saving the user after updating it
Wain
  • 118,658
  • 15
  • 128
  • 151
  • Can you show an example of how this is supposed to be done, or direct me to a link. I'm a beginner in this and there are no good examples. Thanks! – user3784214 Mar 17 '15 at 21:16
  • I'm sorry, I am still very confused at the example. I looked at this one as well and still can't quite figure it out: https://parse.com/docs/data#security-cloudcode – user3784214 Mar 17 '15 at 22:17
  • Would you be able to write an example for this incrementing likes through cloud and objective-c? This is the only cloud code I need for my project, the rest of it I figured out through objective-c and parse. Thanks Wain, and I apologize for my beginnerness. – user3784214 Mar 17 '15 at 22:18
  • You need to try adding the query.get part, the save and the response.success and then edit the question of you still have issues – Wain Mar 18 '15 at 07:40
  • 1
    I would write down a detailed answer with code of what Wain just said, but I think you're better off reading the doc and learning by yourself following Wain's steps. :) – Gil Sand Mar 18 '15 at 10:50