Duplicated item using nextPageAsync

I’m trying to locally persist data from a table so that the user can search for the content offline. I am using this code but when I try to persist the content of the next page in my database, there is a duplicate key error. The nextAsync method is returning items from a previous page among new items.
-(void)nextPageAsync:(BackendlessCollection *)ingredients start:(NSDate *)start {

unsigned long size = [[ingredients getCurrentPage] count];
if (!size) {
NSLog(@“Total time (ms) - %g”, 1000*[[NSDate date] timeIntervalSinceDate:start]);

NSLog(@“Loaded %lu restaurant in the current page”, size);

nextPageAsync:^(BackendlessCollection *ingred) {
[DBManager persistIngredients:ingred.data]; <--------- Duplicate key error here!!!
[self nextPageAsync:ingred start:start];
error:^(Fault *fault) {
NSLog(@“Server reported an error: %@”, fault);

  • (void)updateIngredients
    NSDate *startTime = [NSDate date];

BackendlessDataQuery *query = [BackendlessDataQuery query];
[[backendless.persistenceService of:[Ingredients class]]
response:^(BackendlessCollection *ingredients) {
NSLog(@“Total restaurants in the Backendless storage - %@”, [ingredients getTotalObjects]);
[DBManager persistIngredients:ingredients.data];
[self nextPageAsync:ingredients start:startTime];
error:^(Fault *fault) {
NSLog(@“Server reported an error: %@”, fault);

Please, provide your appID - we will investigate this issue with your data.


My appID is 3636E0F3-A644-8741-FF5D-6D0D0FE1CF00.

Thank you

Hi Rodrigo,

I have created the sample project (see in attachment), it works with your app.
It introduces two scenarios:

  1. Like F17DataPaging example of BlogFeatureDay
  2. Like your example from here.

And both of them work, so we cannot reproduce this issue.

You can try this sample project and check how it works for you.
Load it with TestCDataNextPage.xcworkspace, add your secretKey and run.
In log you can check if retrieved objects are duplicated.


TestCDataNextPage.zip (19.56MB)

Hi Vyacheslav,

I tried to run the example and I’m still getting duplicated itens. To reproduce the behavior, follow the steps below:

1 - Declare a property NSMutableDictionary *ingredientsDictionary;
2 - Change the “persistIngredients:” method for
-(void)persistIngredients:(NSArray *)ingredients {
NSLog(@"\n\nLoaded %lu ingredients in the current page", (unsigned long)ingredients.count);
for (Ingredients *item in ingredients) {
if ([ingredientsDictionary objectForKey:item.objectId] == nil)
[ingredientsDictionary setObject:item forKey:item.objectId];
NSLog(@“Duplicated objectID: %@”,item.objectId);

When I do this, my code is printing some Duplicated objectIDs

But do my original project work for you?

No, still getting duplicate itens filling the dictionary using either basicPaging or updateIngredients.

A solution is to add query.queryOptions.sortBy:

    BackendlessDataQuery *query = [BackendlessDataQuery query];
    query.queryOptions.sortBy = @[@"objectId"];

Ok, it’s working now.

Thank you