I use this code to update my data on data browser on parse.
PFQuery *query = [PFQuery queryWithClassName:#"UserInformation"];
[query getObjectInBackgroundWithId:#"dIwnk9tbr0" block:^(PFObject *gameScore, NSError *error)
{
gameScore[#"email_address"] = #"testkolang#y.com";
[gameScore saveInBackground];
}];
But I have this kind of error. And the data on parse is not changed.
2014-03-12 18:08:06.036 AndroidiOsPushTest[3725:1803] Error: object not found for update (Code: 101, Version: 1.2.18)
PFQuery *query = [PFUser query];
[query getObjectInBackgroundWithId:objectID block:^(PFObject *UserInfo, NSError *error) {
if (!error) {
[UserInfo setObject:self.userName.text forKey:#"username"];
[UserInfo setObject:#"US" forKey:#"country"];
[UserInfo saveInBackground];
}
else {
// Did not find any UserStats for the current user
NSLog(#"Error: %#", error);
}
}];
Your issue looks like the one in : I can not update a record in Parse; Error: "object not found for update (Code: 101, Version: 1.2.16)"
Error code 101 in Parse means :
101: Object doesn't exist, or has an incorrect password.
First, you should check if your object exists and if the error is not null.
Then, if these steps are successful, you should check for the ACL of the object : if you don't have permissions to edit it, you will be unable to save it and get the error 101.
It relate to ACL, please check your dashboard for the data column "ACL"
The write should lock on specific user ID. you need change it from your dashboard to update its permission to
{"*":{"write":true,"read":true}}
You can check more detail on my reply in this
From Parse.com (Hector Ramos)
PFQuery *query = [PFQuery queryWithClassName:#"UserStats"];
[query whereKey:#"user" equalTo:[PFUser currentUser]];
[query getFirstObjectInBackgroundWithBlock:^(PFObject * userStats, NSError *error) {
if (!error) {
// Found UserStats
[userStats setObject:newScore forKey:#"latestScore"];
// Save
[userStats saveInBackground];
} else {
// Did not find any UserStats for the current user
NSLog(#"Error: %#", error);
}
}];
Related
I am trying to search for users which match the searchString. The only thing I'm getting back is me, the current user. No matter what name I type in I get zero results back, but if I type in part of my name then it returns one result with the object (PFUser) representing me when it falls into the parseMembersFromArray method. I have tried alternatives but nothing is working.
PFQuery *query = [PFUser query];
[query whereKey:#"username" matchesRegex:searchString modifiers:#"i"];
[query findObjectsInBackgroundWithBlock:^(NSArray * _Nullable objects, NSError * _Nullable error) {
if (objects.count < 1) {
// Zero results
NSLog(#"No objects found?");
return;
}
if (error) {
// Error
NSLog(#"Something went wrong.");
return;
}
else {
// Good to go
[self parseMembersFromArray:objects];
}
}];
I am using below code to fetch users but I am not able to get it.. app is crashes... Please help me to get all installation objects list..
PFQuery *userQuery = [PFQuery queryWithClassName:#"_Installation"];
[userQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
// The find succeeded.
NSLog(#"Successfully retrieved %d scores.", objects.count);
NSLog(#"objc...%#",objects);
// Do something with the found objects
for (PFObject *object in objects) {
NSLog(#"id...%#",object.objectId);
}
} else {
// Log details of the failure
NSLog(#"Error: %# %#", error, [error userInfo]);
}
}];
Try this:
PFQuery *userQuery = [PFInstallation query];
[userQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
// The find succeeded.
NSLog(#"Successfully retrieved %d scores.", objects.count);
NSLog(#"objc...%#",objects);
// Do something with the found objects
for (PFObject *object in objects) {
NSLog(#"id...%#",object.objectId);
}
} else {
// Log details of the failure
NSLog(#"Error: %# %#", error, [error userInfo]);
}
}];
FYI, Wain is correct in his comment that installations are not users. Are you sure this is the class you want to query?
With Parse, as flexible and sound it is, they are limitations to it. Some are extremely worrying in my opinion as a developer that uses Parse, and some are just implemented server side to protect your end-users. This is one, you can not query the Installation class from a client, the only columns you can query are listed in the API Reference . However, you can query the class through a cloud function using the master key, otherwise, you will have to use a pointer/relation to other tables for whatever data you want to retrieve. Additionally, for future question seekers, please refer to Wains note. It's a valid statement and should be considered prior to proceeding with anything. Users are not installations, the same 'user' i.e., device, can re-download the app multiple times creating numerous installations (not users).
I am having trouble saving a PFRelation I have this code:
//set up the query
PFQuery *query = [PFQuery queryWithClassName:#"messageBank"];
[query whereKey:#"username" equalTo:name];
__weak User *weakSelf = self;
[query getFirstObjectInBackgroundWithBlock:^(PFObject *object, NSError *error) {
if(error) {
NSLog(#"No such user");
handler(NO, error,NO,NO);
}
else{
[weakSelf.friendsRelation addObject:object];
[weakSelf.friends addObject:object];
//save in the background
[weakSelf.messageBank saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if(error) {
NSLog(#"Save error");
}
else {
NSLog(#"no error");
}
}];
handler(YES,nil,NO,NO); //no errors
//so the friend is added to the friends array, all we need to do is reload the table data don't need to init the array again, the relation is also added to the relation item so don't need to init that again
}
}];//end block
My code finds the messageBank object fine but it won't save it to the PFRelation friends. It doesn't even attempt to call [weakSelf.messageBank saveInBackgroundWithBlock.... weakSelf.messageBank is the local PFObject and weakSelf.friends is it's PFRelation. Anyone have any ideas what could be going wrong here? If I have a PFRelation in class A is it okay to have pointers in that relation to other objects in class A? Does it need to be in a different class? Any help would be much appreciated!!!
Here's a cleaned up version of the code that fetches an object and adds to its relation, and saves it...
PFQuery *query = [PFQuery queryWithClassName:#"messageBank"]; // by convention class names should be capital MessageBank, but using yours
[query whereKey:#"username" equalTo:name]; // better form is self.name assuming it is an attribute of self
[query getFirstObjectInBackgroundWithBlock:^(PFObject *object, NSError *error) {
if (!error) {
// see note below about weakSelf
// assume self is a PFObject subclass with two relations
// (and generated setters) called friendsRelation and friends
[self.friendsRelation addObject:object];
[self.friends addObject:object];
// notice we save self here. that's who changed in the two preceding lines
[self saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if(!error) {
// success
} else {
// handle error
}
}];
} else {
// handle error
}
}];
Please notice that there's no need to declare a __weak copy of the self pointer (though, there's no harm in it). That idiom is used to avoid a retain cycle between self and the block's owner. You need it only when self is the blocks owner (directly or indirectly). This isn't the case with parse's completion blocks.
I have a code snippet that will update information in the Parse database. I set up an action so that when the information is saved, it gets updated in the background. The function is being executed, but it's not saving anything on the database. its going through the function, but no changes are being saved. The changed values are inside a text field and a switch.
- (IBAction)save:(id)sender {
NSLog(#"classnameinsave %#", self.productTitleField.text);
PFQuery *query = [PFQuery queryWithClassName:self.className];
[query getObjectInBackgroundWithId:self.productId block:^(PFObject *object, NSError *error) {
NSLog(#"inside getObjectsInBackgroundWithId function");
NSLog(#"priceinsave %#", object[#"price"]);
object[#"title"] = self.productTitleField.text;
object[#"price"] = self.priceField;
object[#"quantity"] = self.quantityField;
object[#"show"] = self.show;
[object saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if(succeeded){
NSLog(#"Succeeded in Saving");
}else if(error){
NSLog(#"Error with saving changes %#", error);
}
}];
}];
}
Most likely this happened because the PFObject you're looking for doesn't even exist! You forgot to add the if statement for verifying if the object exists. Also, I understand you want to make it as dynamic as possible by having the class name based on a UILabel, but please don't do this, this doesn't make sense at all. Replace your code with this:
PFQuery *query = [PFQuery queryWithClassName:#"ClassName"];
[query getObjectInBackgroundWithId:self.productId block:^(PFObject *object, NSError *error) {
if(object){
//Do everything here :)
}else{
//Display an UIAlertView to the user?
NSLog(error);
}
}];
Note: You should add the if statement, however it's not necessary.
Best regards,
I have a class on Parse.com called "Hospital", which has a few rows on it. I want to query all the rows in this object, and then selectively delete some of them.
I figure I need to cycle through the object, gathering the objectIDs, and then look at the row associated with each ID to figure out which ones should be deleted. I can't find how to do this anywhere. I've tried this:
PFQuery *query = [PFQuery queryWithClassName:#"Hospital"];
But this returns an object with 0 objects inside it, when there is definitely a row in the Parse.com database.
Once I get this part working, and get objectIDs, it seems I can delete a row with the following:
PFObject *testObject = [PFObject objectWithoutDataWithClassName:#"Hospital" objectId:#"NMZ8gLj3RE"];
[testObject deleteInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (succeeded){
NSLog(#"BOOOOOM"); // this is my function to refresh the data
} else {
NSLog(#"DELETE ERRIR");
}
}];
PFQuery *query = [PFQuery queryWithClassName:#"Hospital"];
[query findObjectsInBackgroundWithBlock:^(NSArray *hospitals, NSError *error) {
if (!error)
{
for (PFObject *hospital in hospitals)
{
if ([hospital.objectId isEqualToString:#"NMZ8gLj3RE"])
{
[hospital deleteInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (succeeded){
NSLog(#"BOOOOOM"); // this is my function to refresh the data
} else {
NSLog(#"DELETE ERRIR");
}
}];
}
}
}
else
{
NSLog(#"%#",error);
}
}];