1

我在 iOS 上使用原生 Salesforce SDK 离线存储数据并与服务器同步。我可以更新智能存储数据库的条目。当我现在需要同步时,我在 SmartStore API 中找不到使我能够将数据上传到 salesforce 服务器的方法。您能否为我指明如何实现这一目标的正确方向?

4

1 回答 1

1

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 示例

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

于 2013-06-05T11:21:47.537 回答