On our setup the same SF entity is synced to multiple Drupal CTs.

First of all we had an issue with the mapping not considering the corresponding Drupal entity, it has been solved based on the work here: https://www.drupal.org/node/1056630 in patch #35.

We still had issues, becuase the variable which stored the last pull time and also the mapping listing function was relying on the SF entity name.
Now at these places the code has been replaced with the mapping machine_name which gives a much more reliable point of reference.

Comments

gaborpeter created an issue. See original summary.

gaborpeter’s picture

gaborpeter’s picture

StatusFileSize
new2.62 KB
gaborpeter’s picture

More finetuning needed when processing a queued record, to make sure it selects properly the corresponding mapping and content type.

aaronbauman’s picture

This looks like a great solution to me, but is a pretty significant change.
I'd like to get at least one more review before RTBC

asherry’s picture

This patch is a bit outdated and doesn't apply, so for reference on this task I redid the changes with the newest 7.x-3.x. I do think it needs some improvements, so I'll post those afterwards.

asherry’s picture

StatusFileSize
new3.28 KB

my mistake, posted the wrong patch.

asherry’s picture

StatusFileSize
new23.66 KB

Ok I have what I think might be a little more complete solution. In my opinion I also think the code should be refactored a bit to make it easier to test one item at a time, (although obviously this has its complications). I also think with this much changing we'll need some hook_update scripts, so I've added them too.

- New function to get mappings keyed by mapping_name, as redoing the current function (salesforce_get_mapped_objects) would leave it making no sense.
- Rename the queue callback as what it's really doing is processing one queue item, '_process_records' is a bit misleading
- Add mapping_name to queue items (also in above patch)
- Re-save current queue items to make sure they now have the mapping_name
- Delete variables no longer used because of the mapping_name switch
- Simplify salesforce_pull_get_query as this doesn't really need to look through all mappings
- Create two new functions salesforce_pull_create_record, and salesforce_pull_update_record that can then be used for testing and drush scripts.

I'll make a sandbox project too, this is just a first draft. I didn't really add any comments in.

asherry’s picture

Assigned: gaborpeter » Unassigned
nielsonm’s picture

StatusFileSize
new28.62 KB

This patch conflicts with https://www.drupal.org/node/2199951 in drush make - so I've rolled them both into one patch to alleviate this issue.

asherry’s picture

Status: Needs review » Needs work

Just an update on this - I've thought more about my solution and the previous solution by gaborpeter. I actually think the current code in place is the better solution. In the case that there are multiple mappings for the same salesforce object type, querying the object twice (which would happen when looping over mappings instead of salesforce mapped objects) could result in a few undesirable consequences.

- queue items could actually be duplicate salesforce ids
- previous values could be overridden
- the update date would be invalid for the subsequent queries to the same object type

I'm going to rescind my patch and leave this as needs work, but in my opinion it should probably be "closed works as designed". I have however kept the refactoring in my patch and am moving that to another issue, I forked the repo in hopes to create a pull request:
https://github.com/FreeflowDigital/salesforce/tree/refactor-salesforce-pull

aaronbauman’s picture

mrconnerton’s picture

I am having a similar issue but with salesforce_push. I am syncing Drupal Commerce with Salesforce and I need to be able to create Product objects but also PriceBookEntry objects. My plan was to simply map Commerce Product to both, however, while the Product will sync, the Pricebookentry will fail because salesforce_mapping_object doesn't store the ID of the mapping so the product mapping object is loaded when the pricebookentry mapping needs to run.

I'm not sure the best solution around this. I think the simplest solution would be that the salesforce_mapping_object stores the mapping id so when we lookup existing objects or save new ones, we know which mapping that object is for. As long as we prevent the exact same entity type, bundle, object combination more than once, then it will allow the same drupal entity to different salesforce objects.

Unless there is some alternative I'm missing..

markusa’s picture

This would be a killer feature for sure. I'm working on a integration with this module, and it would be super to be able to map one Drupal entity type, to two Salesforce objects...and be able to choose programmatically which salesforce object a entity of each type would push-sync to.

Does anyone here have any success stories of trying that, with the patches here, or otherwise...
using v3.3-beta3

johnny5th’s picture

@mrconnerton I'm trying to solve the exact same issue. Were you able to come up with a solution?

aaronbauman’s picture

Status: Needs work » Closed (won't fix)

7.x is no longer supported

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.