• Resolved fortafy

    (@fortafy)


    I am mapping a custom post type with Contacts in Salesforce. Prematching on Contact ID. Salesforce Key is Contact ID.

    I have had success mapping another custom post type to Accounts but for some reason this just won’t work. Here’s the error message I’m getting:

    Create Salesforce team with WordPress ID with 57193 of Contact was not allowed by this fieldmap.

    Any ideas what this might be related to?

Viewing 15 replies - 1 through 15 (of 17 total)
  • Thread Starter fortafy

    (@fortafy)

    ‘team’ is the custom post type. on the team record I have WordPress User ID and Salesforce ID.

    Plugin Author Jonathan Stegall

    (@jonathanstegall)

    Sure, this log entry happens when for any reason the record is not able to push to Salesforce.

    Possible reasons that the code defines:

    1. It’s trying to update a record that does not exist, and the fieldmap doesn’t allow it to create new records.
    2. It’s trying to push data but the fieldmap only allows it to pull data
    3. a filter has set it to not be allowed

    Thread Starter fortafy

    (@fortafy)

    1. Record and record id are confirmed to exist in Salesforce. I’ve copied the Salesforce ID I’m using and pasting into Saleforce URL.

    2. I have it set with the exact same settings as another custom post type that is working. The one that is working, however, is on Accounts (not Contacts) and it has record types. My Contact does not have any custom Record Types (using Master).

    3. Where would I find filters? Are you referring to the Direction?

    Plugin Author Jonathan Stegall

    (@jonathanstegall)

    1. Okay.

    2. Okay. I don’t think record types would have anything to do with this. The only way your Salesforce setup should affect this particular log entry is if you are also getting error messages from Salesforce, and they would (probably) be separate log entries.

    3. No. Filters are hooks that developers might use to build add-on plugins or themes. In other words, when you write code using add_filter and a method designed to change what the plugin does. There’s a filter that can designate records as not allowed to be pushed.

    The direction value sets whether a specific field can be saved in Salesforce, it doesn’t really have anything to do with whether the whole record can be pushed.

    When you say you’re “Prematching on Contact ID”, why are you doing that, exactly? A prematch field is intended to use a value that might be in WordPress and look for records with that value that would be identical. So for example, a user that has the same email address as a pre-existing contact. I’m not sure why you would use the Contact ID as a prematch, unless you are storing it on the WordPress record?

    If you are storing the contact ID on the WordPress record, is it stored as a meta field on the WordPress user? WordPress can have trouble with that, if so, because metadata doesn’t exist until after the core fields have been saved.

    The Key field doesn’t really have an effect in your case. Salesforce uses that flag to identify custom fields that belong to other systems.

    Thread Starter fortafy

    (@fortafy)

    I’m at a loss. Here is what I’m doing. I have a custom post type I created called ‘team’. The ‘team’ cpt stores user meta and has fields for wp_user_id and sf_contact_id. So no, I’m not using wp_usermeta with the Contact ID.

    The ‘team’ record is created from a Gravity Form which successfully stores both the wp_user_id and sf_contact_id. The Gravity Form also syncs with Salesforce through Gravity Forms for Salesforce successfully.

    All changes should happen in Salesforce and get pulled into the ‘team’ table (source of truth) moving forward. No changes should occur in the ‘team’ table.

    Using the sf_contact_id, I am setting up Object Sync to pull updates from Salesforce into the ‘team’ object in 30 minute asynchronous requests. However, no matter what I do, nothing is syncing. I have removed the Prematch option but am using sf_contact_id as the Salesforce Key.

    Plugin Author Jonathan Stegall

    (@jonathanstegall)

    I still think the key field is not going to do anything for you in this case. Prematch is, like I said, good for matching against a field that is not created when the plugin connects records. Key is not really going to help you because it’s already an ID in Salesforce.

    Aside from that, I’m not sure I can help you further with this; you may need to hire a developer to help you understand what’s happening. But I’ll try to explain as much as possible and you may be on your own after that.

    If you’re storing data for a custom post type in a meta field (so it’s in the wp_postmeta table, in other words), you should be able to pull data from Salesforce into it. This plugin creates rows in the wp_object_sync_sf_object_map table to connect specific records, and then it uses your fieldmap settings to determine what to do with the fields.

    Your original message in this thread has a log entry that is push related. It’s not a pull log entry; it gets created when the plugin is unable to save data in Salesforce. Pull entries would get created when the plugin tries to save data in WordPress.

    In any case, if a field is a meta field and it’s stored in the post meta table, you can, at least theoretically, pull data into it from Salesforce if the records are being properly handled. You should be able to tell if that’s the case from the log entries; every time it runs a query on the Salesforce API it will create a log entry if it’s in debug mode. If it’s pulling the records you expect it to pull, that’s at least a start. If it is pulling the right records but not saving data in WordPress, it should be creating log entries for whatever issue it’s having. If it’s not pulling the records correctly at all, you might be having issues with how the schedule runs.

    If you’re storing data in custom tables, that’s a different question. It might be doable but you’re going to have to write custom code and use the developer hooks, and I can’t provide support for that.

    You might also be running into conflicts with the other plugin. You might want to try creating test records manually, and see if the plugin is able to save data to those meta fields, to determine whether it’s a conflict.

    I’m not sure what else to tell you in this case, and if none of this is helpful I’d recommend looking for a WordPress developer.

    Thread Starter fortafy

    (@fortafy)

    Jonathan, thank you for generosity of time and information. I do have a WordPress developer I can lean on, so that might be might be might next step. Just one last clarifying question. Is it correct to assume that if I’m only pulling records from Salesforce that the record doesn’t have to first exist in WordPress? And if it does exist in WordPress can I use ‘Prematch’ on an unique id like user id to ensure I’m updating an existing record and not creating a new one?

    Plugin Author Jonathan Stegall

    (@jonathanstegall)

    It’s true that if you want to pull records from Salesforce and create new records from them in WordPress, you can do that as long as the “Salesforce Create” checkbox is checked on the fieldmap. This will pull in new records from Salesforce and create them in WordPress.

    Prematch can work to determine if WordPress already has the record, yes. Your specific example is confusing because you’ve been talking about custom WordPress post types and now you’re talking about a WordPress user, but I’ll try to answer. Here’s how it would work:

    1. You could create a fieldmap that mapped the WordPress user object to a Salesforce object.
    2. You could store a WordPress user field value in a field on the Salesforce object.
    3. You could set that field in Salesforce to map to the WordPress user field. I don’t think I would use the ID field because WordPress generates its own user IDs and you wouldn’t know what the ID was before the new record was created. You might be able to make it work, but it feels messy. Your mileage may vary, I guess.
    4. For example, we do this with the email address. We store the email address on the email field for the contact in Salesforce, map it to the user_email field in WordPress, and use that field as a prematch on the user <-> contact fieldmap.
    5. You could use it as a prematch as long as the fieldmap maps the Salesforce field that contains that value to the WordPress field that contains the same value. Then the plugin would look for that value in the corresponding field, and if it found a match it would assume they were the same, and then it would create an object map record between them. Then you could use it to update the record in WordPress.

    Thread Starter fortafy

    (@fortafy)

    Hey Jonathan, me again. I’ve turned on debug and with respect to the syncing this is the SOQL statement I’m seeing in the debug logs:

    SELECT Id, fortafy_wp_id__c, Email, …. WHERE LastModifiedDate > 2021-08-16T15:57:42Z ORDER BY LastModifiedDate ASC LIMIT 100

    Why is it looking for records greater than LastModifiedDate of when the script runs? For example, I modified some records in Salesforce and then ran the Sync. Inevitably it didn’t find any records because the record I modified had a modification date 1 minute less than when I ran the cron.

    I ran the specific query in Workbench and sure enough 0 results.

    Appreciate the help.

    Thread Starter fortafy

    (@fortafy)

    FULL DEBUG LOG ENTRY

    ---
    
    HTTP method: GET
    
    URL of API call to Salesforce: https://timeslipscreativestorytellinginc--fortafyuat.my.salesforce.com/services/data/v52.0/query?q=SELECT+Id%2C+fortafy_wp_id__c%2C+Email%2C+fortafy_occupation__c%2C+fortafy_display_on_web__c%2C+fortafy_training_level__c%2C+fortafy_website__c%2C+MailingCity%2C+MailingState%2C+MailingLongitude%2C+MailingLatitude%2C+MailingCountry%2C+fortafy_facebook__c%2C+fortafy_twitter__c%2C+fortafy_tiktok__c%2C+fortafy_linkedIn__c%2C+fortafy_instagram__c%2C+MailingPostalCode%2C+LastModifiedDate%2C+CreatedDate+FROM+Contact+WHERE+LastModifiedDate+%3E+2021-08-16T15%3A57%3A42Z+ORDER+BY+LastModifiedDate+ASC+LIMIT+100
    
    SOQL query that was sent to Salesforce
    
    SELECT Id, fortafy_wp_id__c, Email, fortafy_occupation__c, fortafy_display_on_web__c, fortafy_training_level__c, fortafy_website__c, MailingCity, MailingState, MailingLongitude, MailingLatitude, MailingCountry, fortafy_facebook__c, fortafy_twitter__c, fortafy_tiktok__c, fortafy_linkedIn__c, fortafy_instagram__c, MailingPostalCode, LastModifiedDate, CreatedDate FROM Contact WHERE LastModifiedDate > 2021-08-16T15:57:42Z ORDER BY LastModifiedDate ASC LIMIT 100
    
    API result from Salesforce
    Array
    (
    [code] => 200
    [data] => Array
    (
    [totalSize] => 0
    [done] => 1
    [records] => Array
    (
    )
    
    )
    
    [from_cache] =>
    [cached] =>
    [is_redo] =>
    )
    • This reply was modified 3 years, 7 months ago by Jan Dembowski.
    • This reply was modified 3 years, 7 months ago by Jan Dembowski. Reason: Formatting
    Plugin Author Jonathan Stegall

    (@jonathanstegall)

    I can’t really speak to why it would do that. The way it’s supposed to work is that every time the query runs, it saves the time in the database so it can use your schedule settings the next time it runs. You might need to change your scheduling settings and see if the plugin fixes its confusion that way.

    Thread Starter fortafy

    (@fortafy)

    I had an ah-ha! and wanted to bounce it off you. We are running 2 different feeds on the same Salesforce Object. The first is User –> Salesforce Contact and is a one way sync from WordPress to Salesforce. The second is a Team (cpt) <– Salesforce Contact and is one way sync from Salesforce to WordPress. Is is possible that having 2 different feeds is causing an issue?

    Plugin Author Jonathan Stegall

    (@jonathanstegall)

    Yes, I do think that is the reason for the last modified issue. The plugin tracks the timestamp when it pulls a Salesforce object type. So in your case, there would be a timestamp for the Contact object that is being updated by both fieldmaps.

    I think we could change it so that timestamp is generated for each fieldmap instead. But to be honest I’m not sure that you wouldn’t run into other issues with trying to run two fieldmaps off the same Salesforce object though. The plugin obviously doesn’t prevent you from doing this, but it also wasn’t built with this in mind.

    In any case, I’m not opposed to adding that change, but I do think it would need a bit of extra testing to make sure that it doesn’t cause conflicts with existing setups.

    Plugin Author Jonathan Stegall

    (@jonathanstegall)

    For the sake of managing the posts here, I’m going to mark this one as resolved. I’ve made a GitHub issue for this. I’d like to get a sense of all the option keys that would have to change for this to work correctly and then do a lot of testing to make sure that changing them to specify which fieldmap they’re related to doesn’t cause conflicts or issues for users who do and who don’t resave their fieldmaps.

    Plugin Author Jonathan Stegall

    (@jonathanstegall)

    @fortafy if you’d be willing, I’ve created a GitHub pull request where I think I have a solid solution for this. I’d love it if you would be willing to test it and see if it works with your situation, as I haven’t really used the plugin the way you were using it. I’d like to make sure the fix works the way it should. Here’s the pull request where the changes are: https://github.com/MinnPost/object-sync-for-salesforce/pull/420

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘Error when syncing to Contact’ is closed to new replies.