Unable to update data object due to ObjectId conflict

I recently imported a Parse database into Backendless. Just a single table of public data, no user auth system or anything. However, there is a simple anonymous voting system that allows you to either notch up or notch down the number of a given object, which is then persisted via a Save action to the backend. In Parse, this was pretty easy. In Backendless, I’m getting this response:

Error: FAULT = '1003' [Cannot persist object. Property 'objectId' must be set by the server. Make sure the property is not initialized when saving new object.

I’m loading them in a map view controller thusly:

BackendlessDataQuery *dataQuery = [BackendlessDataQuery query];

dataQuery.queryOptions = queryOptions;





dataQuery.whereClause = [NSString stringWithFormat:@"distance( %.5f, %.5f, Coordinate.latitude, Coordinate.longitude ) < km(%.1f)", mapView.centerCoordinate.latitude, mapView.centerCoordinate.longitude, [self getRadius] / 1000.0f];

BackendlessCollection *locs = [[backendless.persistenceService of:[Location class]] find:dataQuery];

for (Location *loc in locs.data) {

    [if the location hasn't already been processed, add it to the main array here]

}

Then I pass one of those objects to a detail view, which in turn via user interaction will attempt to save it:

Responder *responder = [Responder responder:self
                                 selResponseHandler:@selector(saveResponseHandler:)
                                    selErrorHandler:@selector(saveErrorHandler:)];
        
NSLog(@"Saving id: %@",activeLocation.objectId);
id&lt;IDataStore&gt; datastore = [backendless.persistenceService of:[Location class]];
[datastore save:activeLocation  responder:responder];

Upon which I get the error. I’m not changing objectId at any point. The NSLog there demonstrates that the objectId being passed is identical to the objectId that shows on the data browser.

This is blocking me, can you help?

Hi Tim,

Could you please show what the Location class looks like?

The logic of the “datastore save” method (on the client side) is to check if a value in the “objectId” property is present. In that case, it calls the update method on the server, otherwise, a method is created. In your case (by looking at the error) it appears the latter is executed.

Mark









#import "Backendless.h"




#define kTypeEat            1

#define kTypePlay           2

#define kTypeLearn          3




#define kVoteUp             1

#define kVoteDown           2




@interface Location : NSObject




@property (nonatomic, strong)              NSNumber* numUpvotes,*numDownvotes;

@property (nonatomic, strong)              NSString *objectId;

@property (nonatomic, strong)              NSString *type;

@property (nonatomic, strong)              NSString *title,*subtype,*Address,*cityStateZipCode,*Review,*Website,*phoneNumber;

@property (nonatomic, strong)              NSString *Latitude,*Longitude;

@property (nonatomic, strong)              GeoPoint *Coordinate;

@property (nonatomic, strong)              NSString *photo;




- (CLLocationCoordinate2D)getCLCoordinate;

- (LocationPin*)getPin;

- (float)getVoteAxis;




- (int)countUpvotes;

- (int)countDownvotes;




@end

Thanks, Tim. This is a bug in our client library:

The code checks for the length of objectId (which is 36 with backendless, but shorter for the objects which came from Parse). We will make the change and republish the library.

Meanwhile, you could try to “pad” the objectId values in the Parse’s export file with extra characters (could be just XXXX-XXXX-XXXX-XXXXX-XXXXX-XXXX) and re-run the import.

Regards,
Mark

Hi Tim,

It has been fixed and you can grab the latest library build from:
https://github.com/Backendless/ios-SDK/blob/master/SDK/lib/backendless/backendless.a

We will update the pod and the download page on the site shortly.

Mark