Unable to update an object (iOS)

I try to update an object by using whereClause to find it and by creating NSDictionary to update it, but it gives me errors.
NSString *whereClause = [NSString stringWithFormat:@“atitle = ‘%@’”, atitle];
DataQueryBuilder *queryBuilder = [[DataQueryBuilder alloc] init];
[queryBuilder setWhereClause:whereClause];

id<IDataStore>dataStore = [backendless.data ofTable:@“menuTable”];
[dataStore find:queryBuilder
response:^(NSArray<NSDictionary<NSString *, id> *> *foundMenu2) {
NSString *obID = [NSString stringWithFormat:@"%@",[foundMenu2 valueForKey:@“objectId”]];

NSDictionary menuNew = @{
@“objectID”: obID,
@“course_1”: _textField.text
};
id<IDataStore> dataStoreSave = [backendless.data ofTable:@“menuTable”];
[dataStoreSave save:menuNew
response:^(NSDictionary<NSString
, id> *contact) {
NSLog(@“Contact saved”);
}
error:^(Fault *fault) {
NSLog(@“Server save reported an error: %@”, fault);
}
];

}
error:^(Fault *fault) {
NSLog(@“Server reported an error: %@”, fault);
}
];
The first error (when I use @“objectID” in the NSDictionary): FAULT = ‘1003’ [Cannot persist object. Property ‘objectId’ must be set by the server. Make sure the property is not initialized when saving new object.] <Cannot persist object. Property ‘objectId’ must be set by the server. Make sure the property is not initialized when saving new object.>
I do totally understand what does this error say but I can not understand how can I update an object without specifying it’s objectId.
The second error (when I use @“objectId” in the NSDictionary): FAULT = ‘1000’ [Entity with name (
“49B27B10-F9DB-B0CB-FFE5-D65970D16900”
) cannot be found] <Entity with name (
“49B27B10-F9DB-B0CB-FFE5-D65970D16900”
) cannot be found>

Have you checked in the debugger if the following returns a valid objectId?:

NSString *obID = [NSString stringWithFormat:@"%@",[foundMenu2 valueForKey:@“objectId”]];

Mark, yes. It returns me: 49B27B10-F9DB-B0CB-FFE5-D65970D16900. The same objectId has an object (the lowest one) which corresponds to my whereClause query.http://support.backendless.com/public/attachments/cb3c3507d1d413276e3750d5f0b49192.png&lt;/img&gt;

cb3c3507d1d413276e3750d5f0b49192.png

Could you try changing the following line:

@"objectID": obID,

to

@"objectId": obID,

Mark, yes, I’ve already tried it. It gives me the second error:

Server save reported an error: FAULT = ‘1000’ [Entity with name (

“49B27B10-F9DB-B0CB-FFE5-D65970D16900”

) cannot be found] <Entity with name (

“49B27B10-F9DB-B0CB-FFE5-D65970D16900”

) cannot be found>

Do you happen to have any event handlers in the app (cloud code)?

Mark, no, I use only Data

If it is important, I’ve renamed the table many times (3 or 4). It was “menu” then I renamed it to “menuTable” and wanted to change it back to “menu”, but even the console gave me the red message error (when I selected the table) that the table with the name “menu” does not exist. So I renamed it back to “menuTable” and I didn’t face any errors messages

Thanks. I opened an internal ticket to investigate the problem (BKNDLSS-14859). Meanwhile, could you please check what version of the SDK library you use?

Mark, I’ve just updated the pod to 4.0b6 today

Hello Vasilii,
Please, check this code:

NSString *whereClause = [NSString stringWithFormat:@"atitle = '%@'", atitle];
 DataQueryBuilder *queryBuilder = [[DataQueryBuilder alloc] init];
 [queryBuilder setWhereClause:whereClause];
 id&lt;IDataStore&gt;dataStore = [backendless.data ofTable:@"menu"];
 
 [dataStore find:queryBuilder
 response:^(NSArray&lt;NSDictionary&lt;NSString*, id&gt; *> *menus) {
 // Here we get all menus which match queryBuilder where clause
 // According to your example we have only one record which matches our where clause
 NSDictionary *menuToChange = [NSDictionary new];
 if (menus.count == 1) {
 menuToChange = menus[0];
 }
 // Changing the menu:
 [menuToChange setValue:_textField.text forKey:@"course_1"];
 // Saving changes:
 [dataStore save:menuToChange
 response:^(NSDictionary&lt;NSString*, id&gt; *changedMenu) {
 NSLog(@"Menu's course_1 changed to: %@", [changedMenu valueForKey:@"course_1"]);
 }
 error:^(Fault *fault) {
 NSLog(@"Server reported an error: %@", fault.message);
 }];
 }
 error:^(Fault *fault) {
 NSLog(@"Server reported an error: %@", fault.message);
 }];

Hope this helps.
By the way the latest version of SDK is 4.0b8, you can check release history here.

Regards, Olga

Olga, thank you! It works!