title: Parse Cloud JS Script - Error Code: 141
body: <p>I've written up a Parse Cloud script in JS which gets called in my Objective-C app. When the script gets called I get an error with the code: 141.
  Here is the code, it gets called when a user accepts a friend request from another user (I'm also not entirely familiar with JS either):</p>
  
  <pre><code>Parse.Cloud.define("addFriendToFriendsRelation", function(request, response) {
  
  Parse.Cloud.useMasterKey();
  
  var friendRequestId = request.params.friendRequest;
  var query = new Parse.Query("FriendRequest");
  
  //get the friend request object
  query.get(friendRequestId, {
  
      success: function(friendRequest) {
  
          //get the user the request was from
          var fromUser = friendRequest.get("from");
          //get the user the request is to
          var toUser = friendRequest.get("to");
  
          var relation = fromUser.relation("friends");
          //add the user the request was to (the accepting user) to the fromUsers friends
          relation.add(toUser);
  
          //save the fromUser
          fromUser.save(null, {
  
              success: function() {
  
                  //saved the user, now edit the request status and save it
                  friendRequest.set("status", "accepted");
                  friendRequest.save(null, {
  
                      success: function() {
  
                          response.success("saved relation and updated friendRequest");
                      }, 
  
                      error: function(error) {
  
                          response.error(error);
                      }
  
                  });
  
              },
  
              error: function(error) {
  
               response.error(error);
  
              }
  
          });
  
      },
  
      error: function(error) {
  
          response.error(error);
  
      }
  
  });
  
  });
  </code></pre>
  
  <p>All help and suggestions are greatly appreciated. Thank you.</p>
  
  <p><strong>EDIT:</strong> In my code I am calling:</p>
  
  <pre><code>[PFCloud callFunctionInBackground:@"addFriendToFriendsRelation" withParameters:@{@"friendRequest" : friendRequest.objectId} block:^(id object, NSError *error) {
  </code></pre>
  
  <p><strong>EDIT2:</strong> The error I am getting in the JS script is the last</p>
  
  <pre><code>        error: function(error) {
  
          response.error(error);
  
      }
  </code></pre>
  
  <p>to be called.</p>