我正在使用iOS上的本机Salesforce SDK脱机存储数据并与服务器同步。我可以将条目更新到智能存储数据库。现在需要同步时,我无法在SmartStore API中找到该方法,该方法使我可以将数据上传到Salesforce服务器。您能否为实现这一目标指明正确的方向?

最佳答案

这不是Smartstore SDK中的方法。您应该执行以下操作:

/**
 * 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();
    }

}

github https://github.com/tomgersic/HazyPassword上有smartsore汤和forcetk的完整样本

我正在开发一个插件来包装此基本流程。

关于iphone - 将离线记录从Salesforce iPhone native 应用程序同步到Salesforce(使用SmartStore),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16937042/

10-11 17:12