MinnPost / object-sync-for-salesforce

WordPress plugin that maps and syncs data between Salesforce objects and WordPress objects.
https://wordpress.org/plugins/object-sync-for-salesforce/
GNU General Public License v2.0
96 stars 52 forks source link

Manual pull creates duplicate records #385

Closed jonathanstegall closed 3 years ago

jonathanstegall commented 3 years ago

Describe the bug It's possible that something in the 1.9.8 release has caused the manual_pull method to create duplicate records. See https://github.com/MinnPost/object-sync-for-salesforce/issues/360#issuecomment-800355323_ for more.

jonathanstegall commented 3 years ago

Here's the code difference between 1.9.7 and 1.9.8.

jonathanstegall commented 3 years ago

@afgarcia86 if you'd like to track this issue (or if you discover what is causing it), please discuss here.

jonathanstegall commented 3 years ago

I was hoping to reproduce this and try to fix issues that might exist for version 1.9.9. But I've run the manual pull on a standard fieldmap (contacts to users) and it doesn't create duplicate records. It may be that there's a specific case that can cause this to happen, but for now I'm going to say it still needs further work to replicate it, and I'm not going to hold 1.9.9 for it.

afgarcia86 commented 3 years ago

It was an account that was having issues and it was creating the duplicate in Salesforce. I will get everything running locally sometime this week or next and try to recreate it again.

afgarcia86 commented 3 years ago

😨 I made a discovery this morning that may be the root of my issue. If I uninstall the plugin does it lose all of its mappings? I just queried the wp_object_sync_sf_object_map and only have like 4 records.

afgarcia86 commented 3 years ago

image

Was not checked..

jonathanstegall commented 3 years ago

You can check the wp_object_sync_sf_field_map and wp_object_sync_sf_object_map tables, but I've certainly never seen it delete records from those tables when it was uninstalled, unless that box was checked.

afgarcia86 commented 3 years ago

Could I be that I deleted the plugin manually to copy over the version from github? The folder name changed.

On Thu, Mar 18, 2021 at 9:33 AM Jonathan Stegall @.***> wrote:

You can check the wp_object_sync_sf_field_map and wp_object_sync_sf_object_map tables, but I've certainly never seen it delete records from those tables when it was uninstalled, unless that box was checked.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/MinnPost/object-sync-for-salesforce/issues/385#issuecomment-801929358, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA3QMJOKFMMMI6ZTIVUAB4LTEH6KJANCNFSM4ZIZMS6A .

-- Best Regards,

Andres Garcia Software Engineer http://www.andresthegiant.comhttp://www.andresthegiant.com 703.389.1081

jonathanstegall commented 3 years ago

I can't speak to that. It would be weird to run it under a different name, so I'm not sure what it would do. The plugin certainly does not have instructions to delete tables without being uninstalled with that checkbox.

afgarcia86 commented 3 years ago

All good, I am just going to try to prevent pushing records created before this date until I am able to sort this out.

afgarcia86 commented 3 years ago

Sorry for the potentially false alarm here. I will report back if I figure out what went wrong on my end.

afgarcia86 commented 3 years ago

Ok so on my end I added more to my object_sync_for_salesforce_push_object_allowed which is helping me prevent duplicates from being generated. So not 100% sure why its happening but I have a way to stop it.

Curious if you have any tips for how I can re-sync the various objects I have. I saved the Salesforce ID to a custom field on my custom post types so if you have a good idea for a script I can use I would be extremely grateful.

jonathanstegall commented 3 years ago

I don't think I understand the question. You can import the objects, but I'm assuming you already know how to do that. If you want to force them all to update in Salesforce, one thing you could do is add a custom field with a placeholder value. Maybe like a field with a single letter in it and you just update that value when the records need to update.

If you need to bulk update the records in WordPress, I'm not really sure how to do that. I think it is probably risky since WordPress doesn't have a way to queue things on its own. But there's probably a bulk update plugin somewhere that you could try.

afgarcia86 commented 3 years ago

So my problem is I now have a bunch of records in WordPress & in Salesforce but they are not mapped anymore. So right now if I update a WordPress record it triggers a Create in Salesforce.

I am wondering if there is a way I can manually re-map the existing WP Posts to SF Records so that they are back in sync.

jonathanstegall commented 3 years ago

Yes, you can do that via the import functionality. It is pretty manual though. You'd need to generate the JSON somehow, maybe via your own PHP script.

If you do an export you can see what the JSON needs to look like, but I don't have a way to generate that JSON out of existing data.

afgarcia86 commented 3 years ago

Hmm now I feel like I am missing something, if I remember correctly the JSON would look like:

{ "object_maps": [ { "wordpress_object": "user", "object_type": "Contact", "salesforce_id": "0035w000034dIMuAAA" } ]}

However if I look at manual_pull it only takes in $object_type, $salesforce_id so I don't think $wordpress_object is used anymore. Also wouldn't I want to add $wordpress_id so that it doesn't create a record from scratch.

jonathanstegall commented 3 years ago

There's some documentation about how import works here: https://github.com/MinnPost/object-sync-for-salesforce/blob/master/docs/import-export.md

But briefly, it doesn't use manual_pull, it uses the import_json_file method.

afgarcia86 commented 3 years ago

Oh ok that is super helpful I guess I was reading the code wrong. Thanks!

jonathanstegall commented 3 years ago

You can read that method here. Manual pull is the one that gets used by the REST API (in some cases) and by the box that manually pulls data into a user record.

afgarcia86 commented 3 years ago

Ah got it! Thanks Again

So I would need something like:

{
    "object_maps":[{
        "wordpress_id": ID,
        "wordpress_object": POST_TYPE,
        "salesforce_id": SALESFORCE_ID,
        "object_type": SALESFORCE_TYPE,
    }]
}
jonathanstegall commented 3 years ago

I would still very much recommend you do an export of existing data from the plugin to make sure you have it in a matching format.

jonathanstegall commented 3 years ago

This one has been inactive for some time, so I'm going to mark it as resolved for now.