Saving a user causes Error: object not found for update (Code: 101, Version: 1.2.19)
[PFGeoPoint geoPointForCurrentLocationInBackground:^(PFGeoPoint *geoP
I have the same problem as you, I done some testing and figure out root cause:
Works ACL, I done modify for * to make it clear
Failed ACL.
As you could see the write privilege lock to user "6iIv5XWZvM", that's why your update will "not found object"
You could change data record directly to "*" to let your update works well.
OK! Here is solution as follow:
Change every record "ACL" data col as follow:
{"*":{"write":true,"read":true}}
You need login PFUSer as specific user to change ACL to public. For my case use objectId will be "6iIv5XWZvM". I need set password and login info and use code to login and modify it. Detail iOS code as follow:
//iOS Sample
[PFUser logInWithUsernameInBackground:@"USERNAME" password:@"PASSWORD" block:^(PFUser *user, NSError *error) {
if (user) {
PFQuery *query = [PFQuery queryWithClassName:CLASS_NAME];
[query findObjectsInBackgroundWithBlock:^(NSArray *objs, NSError *error) {
for (PFObject *obj in objs) {
PFACL *defaultACL = [PFACL ACL];
[defaultACL setPublicReadAccess:YES];
[defaultACL setPublicWriteAccess:YES];
[obj setACL:defaultACL];
[obj saveInBackground];
}
}];
} else {
// The login failed. Check error to see why.
}
}];
However remember to add following setting before you save new data, if you don't want to happen anymore (note: it will be security concern)
//It is iOS code sample.
PFACL *defaultACL = [PFACL ACL];
[defaultACL setPublicReadAccess:YES];
[defaultACL setPublicWriteAccess:YES];
[PFACL setDefaultACL:defaultACL withAccessForCurrentUser:YES];
The error : "object not found for update" append when the you try to save an object that the user does not have ACL access.
In order to let the user change the object you need to set PFACL permission when you create the object :
For a specific user :
PFObject *object = /*the object you want to save*/
NSString *userID = /*the objectID of the user you want to let perform modifications later*/
PFACL *groupACL = [PFACL ACL];
[groupACL setWriteAccess:YES forUserId:userID];
object.ACL = groupACL;
For a all users :
PFObject *object = /*the object you want to save*/
NSString *userID = /*the objectID of the user you want to let perform modifications later*/
PFACL *groupACL = [PFACL ACL];
[groupACL setPublicWriteAccess:YES];
object.ACL = groupACL;
Try this, i'm using this, when i need to save objects for the current user. Hope it will help.
PFUser *user = [PFUser currentUser];
[user setObject:geoPoint forKey:@"location"];
[user saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (error){
NSLog(@"Error %@ %@", error, [error userInfo]);
}
}];