function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jyoti Singh 9Jyoti Singh 9 

Pagination for SmartStore in iOS SDK

Can anyone tell me how can I paginate the records in SmartStore for an app built using Salesforce iOS SDK. I am currently doing
 
- (NSArray*)query:(NSString*)queryString
{
    SFQuerySpec *querySpec = [SFQuerySpec newSmartQuerySpec:queryString];
    int count = [self.store countWithQuerySpec:querySpec error:nil];
    querySpec = [SFQuerySpec newSmartQuerySpec:queryString ];
    return [self.store queryWithQuerySpec:querySpec error:nil];
}

Please help
Best Answer chosen by Jyoti Singh 9
Gaurav KheterpalGaurav Kheterpal
You can do it by including the pagination parameters similar to below

 
- (NSArray*)query:(NSString*)queryString
{
    SFQuerySpec *querySpec = [SFQuerySpec newSmartQuerySpec:queryString withPageSize:10];
    int count = [self.store countWithQuerySpec:querySpec error:nil];
    querySpec = [SFQuerySpec newSmartQuerySpec:queryString withPageSize:count];
    return [self.store queryWithQuerySpec:querySpec pageIndex:0 error:nil];
}

The key is to

* use withPageSize to specify the pagesize
* Do a count of the records
* Set the withPageSize while querying the store
* Set starting page Index to 0

If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others and improve the overall quality of Discussion Forums.

Gaurav Kheterpal
Certified Force.com Developer| Salesforce Mobile Evangelist| Developer Forums Moderator| Dreamforce Speaker