Question

I am using the native Salesforce SDK on iOS to store data offline and synchronize with the server. I can update entries to the smartstore database. When I need to synchronize now I couldn't find the method in the SmartStore API which enables me to upload data to the salesforce server. Would you be able to point me in the right direction on how to achieve this?

Was it helpful?

Solution

Ther is not a method in the smartstore sdk. You should do something like this:

/**
 * Upload Queue to Salesforce
 **/
OfflineQueue.UploadQueue = function(callback,error) {
    console.log("OfflineQueue.UploadQueue");
    if(Util.checkConnection()) {
        console.log("OfflineQueue.UploadQueue -- app is online");
        //DF12 DEMO 23 -- UPLOAD QUEUE TO SFDC
        navigator.smartstore.soupExists('Queue',function(param){
            if(param)
            {
                console.log("OfflineQueue.UploadQueue -- Queue exists");
                OfflineQueue.LoadRecordsFromQueue(function(records) {
                    if(records.length==0){
                        console.log("OfflineQueue.UploadQueue -- no records in queue");
                        callback();
                    }
                    else {              
                        console.log("OfflineQueue.UploadQueue -- iterating records");
                        for(i in records){
                            forcetkClient.update('Password__c',records[i].Id,{"Username__c":records[i].Username__c,"Password__c":records[i].Password__c,"Name":records[i].Name,"URL__c":records[i].URL__c},function(){
                                console.log('QUEUED SFDC Update Success!');
                                //DF12 DEMO 24 -- ON SUCCESS, REMOVE RECORD FROM QUEUE
                                navigator.smartstore.removeFromSoup('Queue',[records[i]._soupEntryId],function(){
                                    console.log('Removed from Soup');
                                    if(i == records.length-1) {
                                        callback();
                                    }
                                },error);
                            },error);               
                        }
                    }
                },error);
            }
            else {
                console.log("Offline queue doesn't exist yet... must not be any records there...")
                callback();
            }
        },error);


    }
    else {
        console.log("We're offline, can't upload queue... how'd we even get here?")
        callback();
    }

}

There is a complete sample of smartsore soups and forcetk on github https://github.com/tomgersic/HazyPassword

I'm working on a plugin to wrapp this basic flow.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top