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
Will HellingWill Helling 

iOS SmartStore/SmartSync creating related records offline before ids are created

We're using SmartSync and SmartStore on native iOS to create some data... The general model is that a user will go to a location, create a record of that visit and then create associated survey records that are connected to that record. My question is what is the best practices way to make sure that two objects in a parent-child relationship that have been created offline (and thus neither have an id) can be properly connected to each other on the reSync call?

My first thought was to use _soupEntryId to create a sort of temporary foreign key field between the two and then update the real foreignId field when the sync happens (and then sync again). However this has two problems:
  1. How can I get a list from SmartSync of all the objects that were updated during a sync? Do I have to just fetch every object in the database and deal with it as though it were updated?
  2. I haven't found a way to run an SFQuerySpec on a soup against any field that isn't Id. I see that all my custom data is stored in the record inside a field that basically just stores json, but I can't really query it directly. Would this mean I'd have to load all the objects from SmartStore and loop through them individually to match against a custom field?
We also noticed that there are a few classes, SFParentChildrenSyncUpTarget for example, that seem to address this. However we're not sure how to use this when the ids of the objects haven't yet been set... How would salesforce know what specific records we want linked together?

Any help would be much appreciated.
Todd Halfpenny MCTodd Halfpenny MC
Hi Will,

I'm unsure as to the specifics of this with SmartSync, though your approach seems to be sensible. This is how we do it internally with MobileCaddy, and as a dev if you were to use our framework then you'd get full offline (including multi tier parent/child creation) out  of the box. If you'd like some info here's a quick link to our guide for defining this (http://developer.mobilecaddy.net/docs/developer-guide/creating-masterdetail-lookup-relationships/);

If you'd like more info on MobileCaddy, then please feel free to ping me,
sheryl brocksheryl brock