You need to sign in to do that
Don't have an account?
Vladimir Bessonov
userstore and usersync iOS sdk
HI. I cannot find examples of how to use userstore and usersync
I am trying to build iOS project
I added my configs
Error I get
I am trying to build iOS project
I added my configs
{ "soups": [ { "soupName": "Account", "indexes": [ { "path": "Id", "type": "string"}, { "path": "Name", "type": "string"}, { "path": "Industry", "type": "string"}, { "path": "__local__", "type": "string"} ] }, { "soupName": "Office", "indexes": [ { "path": "Id", "type": "string"}, { "path": "Name", "type": "string"}, ] } ] }
{ "syncs": [ { "syncName": "syncDownAccounts", "syncType": "syncDown", "soupName": "Account", "target": {"type": "soql", "query":"SELECT Id, Name, Industry FROM Account LIMIT 25"}, "options": {"fieldlist":["Id", "Name", "Industry", "LastModifiedDate"], "mergeMode":"LEAVE_IF_CHANGED"} }, { "syncName": "syncDownOffices", "syncType": "syncDown", "soupName": "Office", "target": {"type": "soql", "query":"SELECT Id, Name FROM Account LIMIT 25"}, "options": {"fieldlist":["Id", "Name", "Industry"], "mergeMode":"LEAVE_IF_CHANGED"} } ] }My Model.swift is copy paste from example project iOSNative, but it does not work
import Combine import SmartStore import MobileSync import CoreLocation /** Model object for an office */ struct Office: Hashable, Identifiable, Decodable { let id: String let name: String // var coordinates: Coordinates // // var locationCoordinate: CLLocationCoordinate2D { // CLLocationCoordinate2D( // latitude: coordinates.latitude, // longitude: coordinates.longitude) // } } /** ViewModel for Account List */ class OfficeListModel: ObservableObject { @Published var offices: [Office] = [] var store: SmartStore? var syncManager: SyncManager? private var syncTaskCancellable: AnyCancellable? private var storeTaskCancellable: AnyCancellable? init() { store = SmartStore.shared(withName: SmartStore.defaultStoreName) syncManager = SyncManager.sharedInstance(store: store!) } func fetchOffices() { syncTaskCancellable = syncManager?.publisher(for: "syncDownOffices") .receive(on: RunLoop.main) .sink(receiveCompletion: { _ in }, receiveValue: { _ in self.loadOfficeFromSmartStore() }) self.loadOfficeFromSmartStore() } private func loadOfficeFromSmartStore() { storeTaskCancellable = self.store?.publisher(for: "select {Office__c:Name}, {Office__c:Id}, {Office__c:LastModifiedDate} from {Office__c}") .receive(on: RunLoop.main) .tryMap { $0.map { (row) -> Office in let r = row as! [String?] return Office(id: r[1] ?? "", name: r[0] ?? "" ) } } .catch { error -> Just<[Office]> in print(error) return Just([Office]()) } .assign(to: \OfficeListModel.offices, on:self) } } struct Coordinates: Hashable, Codable { var latitude: Double var longitude: Double }
Error I get
020-10-03 23:46:06.332646-0700 iOS13NativeSwiftTemplate[6701:459960] [MobileSync] CLASS: SFSyncDownTask runSync failed:{ "soupName" : "Office", "options" : { "fieldlist" : [ "Id", "Name", "LastModifiedDate" ], "mergeMode" : "LEAVE_IF_CHANGED" }, "error" : "{\n error = (\n {\n errorCode = \"MALFORMED_QUERY\";\n message = \"\\nselect LastModifiedDate,Id, Name, from Office__c order by LastModifiedDate\\n ^\\nERROR at Row:1:Column:34\\nunexpected token: 'from'\";\n }\n );\n}", "_soupEntryId" : 2, "maxTimeStamp" : -1, "type" : "syncDown", "progress" : 0, "endTime" : 1601793936278, "target" : { "idFieldName" : "Id", "modificationDateFieldName" : "LastModifiedDate", "iOSImpl" : "SFSoqlSyncDownTarget", "type" : "soql", "query" : "select LastModifiedDate,Id, Name, from Office__c order by LastModifiedDate" }, "totalSize" : -1, "startTime" : 1601793965564, "status" : "RUNNING", "name" : "syncDownOffices" } cause:Server call for sync down failed errorError Domain=com.salesforce.RestAPI.ErrorDomain Code=400 "(null)" UserInfo={error=( { errorCode = "MALFORMED_QUERY"; message = "\nselect LastModifiedDate,Id, Name, from Office__c order by LastModifiedDate\n ^\nERROR at Row:1:Column:34\nunexpected token: 'from'"; } )}
This might relate to your query.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Thanks.