I'm having some trouble working out the logistics behind creating two records on separate objects that have a lookup relationship.
Lets say we're offline and want to create an Account, and then add a Contact. Since we're not able to connect to SFDC, we won't know what value to set in Contact.AccountId. Instead we create a field on the Contact soup, call it _accountSoupEntryId
, that stores the value of _soupEntryId
for the Account it is related to.
I'm unclear on what to do when we sync our soups up to Salesforce. I thought there would be some functionality that would assist with setting lookup fields for objects that are related as is described here.
I understand that the following has to occur:
- Accounts get created, and re-sync'd with their soup which will give them a proper Salesforce Id.
- Contacts get their AccountId field updated locally by looking up to the Account soup.
- Contacts are then able to be sync'd up to Salesforce.
Do I need to handle this manually?
Is this going to involve creating a custom sync target, or is there some functionality that I haven't found yet for assisting with this?
What about syncing down, is there an easy way to populate _accountSoupEntryId
on the Contact when we Sync Down so that I don't need to handle displaying lookup fields differently based upon whether or not that particular soup entry is sync'd (e.g. has a proper Salesforce Id)?
_AccountId
that is used to hold the _soupEntryId of the Account the Contact is related to. When I run a "Sync Up" operation, I sync the Accounts first. Then I query the Contact soup to find any Contacts that have a value in_AccountId
, but do not have a value inAccountId
and update theAccountId
field with the value of the newly sync'd account. Then the Contact soup can be sync'd.