0
votes

I am trying to update a chat object I have saved with Parse, and although it works sometimes, it's not consistent. If I clear the object out of data on the browser side, it will work a few times, but then I get the error:

Error: object not found for update (Code: 101, Version: 1.3.0)

Here is the code I am using, although I've tried many ways. This code is nearly identical to the Parse documentation.

PFObject *currentChatroom = _currentChatroom;
    NSString *objID = currentChatroom.objectId;
    PFQuery *query = [PFQuery queryWithClassName:@"Chats"];

    // Retrieve the object by id
    [query getObjectInBackgroundWithId:objID block:^(PFObject *fetchedChat, NSError *error) {

        // Now let's update it with some new data. In this case, only cheatMode and score
        // will get sent to the cloud. playerName hasn't changed.
        fetchedChat[@"lastTextSent"] = lastTextWithUser;
        fetchedChat[@"lastTextSentDate"] = date;
        [fetchedChat saveInBackground];

    }];

For good measure, Here is the Parse recommendation:

PFQuery *query = [PFQuery queryWithClassName:@"GameScore"];

// Retrieve the object by id
[query getObjectInBackgroundWithId:@"xWMyZ4YEGZ" block:^(PFObject *gameScore, NSError *error) {

    // Now let's update it with some new data. In this case, only cheatMode and score
    // will get sent to the cloud. playerName hasn't changed.
    gameScore[@"cheatMode"] = @YES;
    gameScore[@"score"] = @1338;
    [gameScore saveInBackground];

}];

The Code works sometimes, so I know that's not the issue. I'm just not sure what is.

1

1 Answers

-1
votes

The code I used to fix this problem was allowing each user of the object (chatroom in this case) to have ACL Permissions to edit (writeAccess) the PFObject when it was first created. In order to do this, I used the code:

         PFObject *newChatroom = [PFObject objectWithClassName:@"Chats"];

            // Create ACL to allow both users to edit/update the chatroom
         PFACL *multipleUserRights = [PFACL ACL];

            // _currentFriend is one user in the chatroom
         [multipleUserRights setReadAccess:YES forUser:_currentFriend];
         [multipleUserRights setWriteAccess:YES forUser:_currentFriend];

            // Give the current user permission as well 
         [multipleUserRights setReadAccess:YES forUser:[PFUser currentUser]];
         [multipleUserRights setWriteAccess:YES forUser:[PFUser currentUser]];

         newChatroom.ACL = multipleUserRights;

I found similar questions to this, and some had similar solutions, but not with the error 1.3.0, so I wouldn't consider it a duplicate.