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
som raysom ray 

SFRestAPI related query

Hi All,
Not sure whether i am in the right forum for my question as i am a newbie to Salesforce. I have a couple of questions.
I am developing an app which connects to SFDC to retrieve records and show them as per the app business logic. This app has Offline capability and I am using Smartstore API to store the data in offline. I am using SFRestAPI to synchronise the data to and fro in the SFDC server. I have a connection manager class that takes care of the rest calls, i.e, build the queryspec and pass it to the SFRestAPI+Blocks API.
1. How can i manage the response of the calls, since the responses comes asynchronously from the API. I mean i need to show a HUD loading mask above my view untill all my data is downloaded. But i am not finding any suitable way to track this  from the API, so that i can remove the HUD mask on a callback.
2. Is there any way to send an array of insert objects/update objects to the REST web service of SFDC through SFRestAPI. I mean when i will query my soup for the locally inserted/updated records, i will receive an array of record. Now what i am doing is looping through the array and creating each connection for each row, this is increasing my network traffic and also my code complex.
I will be thankful to all of you for your support.

Thanks again in advance.
Som
Gaurav KheterpalGaurav Kheterpal
Hello Som,

This is the right forum to be asking your questions. Additionally, if you have Mobile SDK specific questions, you can always post them in the Mobile SDK Google+ community (https://plus.google.com/u/1/communities/114225252149514546445?cfem=1)as well.

For both questions, you didn't really specify if your app is A) Native or hybrid B) Whether you're building it for iOS or Android

It will also help if you can provide your code snippet. I'll be able to help further once you provide the mentioned inputs.

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

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

 
som raysom ray
Thanks Gaurav for your response.
I missed out mentioning that i am building the app around ios 7+. and the app is a native application.
Please find below my view model class which calls the connection manager instance and fetch the data from the server. 
-(void)fetchAllDetailsFromServer:(void(^)(BOOL success)) completionBlock
{
    @autoreleasepool {
        ConnectionManager *connectionObj =  [ConnectionManager sharedManager];
        DatabaseManager *dbManager = [DatabaseManager sharedManager];
        [connectionObj fetchUsersWithCompletionHandler:^(BOOL status, NSArray *responseData){
            if (status && responseData.count) {
                BOOL IS_dataInsertedInLocalDB = [dbManager insertAccountPlanOwners:responseData];
                if (IS_dataInsertedInLocalDB) {
                    NSLog(@"user data inserted>>>>>>>>>>>>>>>>>");
                }
            }
        }];
        [connectionObj fetchCustomersWithCompletionHandler:^(BOOL status, NSArray *responseData) {
            if (status && responseData.count) {
                BOOL IS_dataInsertedInLocalDB = [dbManager insertCustomers:responseData];
                if (IS_dataInsertedInLocalDB) {
                    NSLog(@"customer data inserted<<<<<<<<<<<<<<<<");
                }
            }
        }];
        [connectionObj fetchKeyCustomersWithCompletionHandler:^(BOOL status, NSArray *responseData) {
            if (status && responseData.count) {
                BOOL IS_dataInsertedInLocalDB = [dbManager insertkeyCustomers:responseData];
                if (IS_dataInsertedInLocalDB) {
                    NSLog(@"key customers data inserted$$$$$$$$$$$$$$$");
                }
            }
        }];
        [connectionObj fetchTacticsWithCompletionHandler:^(BOOL status, NSArray *responseData) {
            if (status && responseData.count) {
                BOOL IS_dataInsertedInLocalDB = [dbManager insertTactics:responseData];
                if (IS_dataInsertedInLocalDB) {
                    NSLog(@"tactics data inserted###################");
                }
            }
        }];
        [connectionObj fetchTeamMembersWithCompletionHandler:^(BOOL status, NSArray *responseData) {
            if (status && responseData.count) {
                BOOL IS_dataInsertedInLocalDB = [dbManager insertTeamMembers:responseData];
                if (IS_dataInsertedInLocalDB) {
                    NSLog(@"team members data inserted@@@@@@@@@@@@@@@@@@");
                }
            }
        }];
        [connectionObj fetchProductsWithCompletionHandler:^(BOOL status, NSArray *responseData) {
            if (status && responseData.count) {
                BOOL IS_dataInsertedInLocalDB = [dbManager insertProducts:responseData];
                if (IS_dataInsertedInLocalDB) {
                    NSLog(@"products data inserted!!!!!!!!!!!!!!!!!!!!!!");
                }
            }
        }];
    }
}
Please find below the the code module that calls the SFRestAPI methods and fetch the data from the SFDC server.
NSString *selectQuery = [SFRestAPI SOQLQueryWithFields:_accountPlanOwnerMasterListArray sObject:kAccountPlanOwnerSoupName where:[NSString stringWithFormat:@"%@.%@ = true AND %@.%@ > %@", kAccountPlanOwnerSoupName, kIsActiveUserkey, kAccountPlanOwnerSoupName, kLastModifiedDateKey, [[NSUserDefaults standardUserDefaults] valueForKey:kAccountPlanOwnerLastDownloadedKey]] limit:0];
    SFRestRequest *request = [[SFRestAPI sharedInstance] performSOQLQuery:selectQuery failBlock:^(NSError *e) {
        if (e) {
            NSLog(@"All Active AccountPlanOwners download error description :: %@", [e description]);
            if (completionHandler) {
                completionHandler([NSArray array], NO);
            }
        }
    }completeBlock:^(NSDictionary *dict) {
        NSArray* accPlanOwnerDetails = [dict valueForKey:@"records"];
        //NSLog(@"accountPlanOwnerMasterListArray ::%@", accPlanOwnerDetails);
        [[NSUserDefaults standardUserDefaults] setValue:[SFDateUtil toSOQLDateTimeString:[NSDate date] isDateTime:YES]forKey:kAccountPlanOwnerLastDownloadedKey];
        [[NSUserDefaults standardUserDefaults] synchronize];
        if (completionHandler) {
            completionHandler(accPlanOwnerDetails, YES);
            accPlanOwnerDetails = nil;
        }
    }];
    return request;

Now my questions are based on the the first code snippet. 
1. How can i manage the response of the calls, since the responses comes asynchronously from the API. I mean i need to show a HUD loading mask above my view untill all my data is downloaded. But i am not finding any suitable way to track this  from the API, so that i can remove the HUD mask on a callback. I want to have something like dispatch_notify does in case of dispatch groups.