Prevent User Object Creation on Sync
-
Is there any way to prevent user creation on sync through the built-in plugin settings/hooks? I’d like WordPress to pull contact data when manually creating a user on WP, but not have a new user created when data is updated in Salesforce. I still want EXISTING wordpress sync’d users to receive data updates from Salesforce though.
Currently I’ve accomplished this by commenting out parts of the create_user() function, but this practice does throw some errors and may cause some issues that I haven’t come across or troubleshot yet. Just wondering if there’s something I’m missing in the developer hooks that would accommodate this. Thanks.
-
So when you’re editing a fieldmap, the Action Triggers section reads like this:
WordPress Create
WordPress Update
WordPress Delete
Salesforce Create
Salesforce Update
Salesforce DeleteWhat we do at MinnPost is check the “Salesforce Update” box but not the “Salesforce Create” box; this allows us to sync updates from Salesforce into WordPress records that are connected.
Are you saying this doesn’t work for you?
Thanks for the quick response!
I don’t want all users to necessarily exist in WP that exist in SF. So if say, an address were updated in SF, but that contact doesn’t have an associated WP User, that action would create a new user account in WP, which is what I’m trying to avoid.
What tipped this off though is that the client added a field to all SF contacts, which started pulling/creating users in the same effect that the system modstamp workaround does.
Well, if you update a record in Salesforce but you don’t check the “Salesforce create” box, it won’t create a new user in WordPress. It doesn’t for us, in any case. Are you saying that doesn’t work for you?
Oh boy, well I feel like a dummy. Sorry about that. I had SF Create selected on the new map… Doesn’t appear to be creating user accounts now. Thanks for clearing that up. I appreciate it!
-
This reply was modified 4 years, 2 months ago by
mmer12.
A little update: No longer are users being created on update, but now there is no pull request after creating a user in WP…
Ideally I’d like the the map to check and pull from SF when a new WP User signs up, but it seems like the Create SF trigger is what used to do that. Could I use the
object_sync_for_salesforce_push_successhook to request a pull? Would you be able to tell me what that should look like?Thanks again!
You could certainly do a pull after a push success. I don’t really do support for the developer hooks, but I think if you used
object_sync_for_salesforce_push_success, the easiest thing would be to make a REST API call to the plugin to pull the record. There isn’t a lot of documentation about how to use the REST API endpoints, but the endpoints are listed here.add_action( 'object_sync_for_salesforce_push_success', 'pull_this_record', 10, 5 ); function pull_this_record( $op, $sf_response, $synced_object, $object_id, $wordpress_id_field_name ) { if ( 'Create' === $op ) { // run a rest api call here where you pass the Salesforce object ID and the Salesforce object type // example parameters: $salesforce_id = $object_id; $salesforce_object_type = 'Contact'; } }You might have to tweak some of this, and of course figure out how you want to make REST calls and handle the response. But I do think that is easier.
Alternatively, you could certainly load one of the plugin’s classes and do it that way, but I think that is riskier in case classes were to get renamed or split up in the future.
Awesome. Thanks so much! I’ll tweak this a bit and see where I get.
Running into another issue now!
From the documentation as I understood it, I didn’t necessarily need a response to trigger the plugin to pull the data, correct? I should be able to make a POST request containing the
salesforce_idandsalesforce_object_typeto the /pull url and the plugin would accept those parameters and update accordingly?So I’ve tried a number of ways to POST to “/wp-json/object-sync-for-salesforce/pull”, including sending a request with Postman, but I’m not getting any responses back except for
200 OK.Code below
add_action( 'object_sync_for_salesforce_push_success', 'pull_this_record', 10, 5 ); function pull_this_record( $op, $sf_response, $synced_object, $object_id, $wordpress_id_field_name ) { if ( 'Upsert' === $op ) { $salesforce_id = $object_id; $salesforce_object_type = 'Contact'; $url = 'https://[domain.com]/wp-json/object-sync-for-salesforce/pull'; $my_args = array( 'method' => 'POST', 'salesforce_id' => $salesforce_id, 'salesforce_object_type' => $salesforce_object_type); wp_remote_post($url, $my_args); } };What am I missing here?
-
This reply was modified 4 years, 2 months ago by
mmer12.
Well, when you run a pull request through the API, what it does is run a sync so the record itself should be updated. It isn’t going to return data for you through the API though, if that makes sense.
Yeah, that makes sense… So it’s weird then that when I hard-code the function like so…
$url = 'https://[domain.com]/wp-json/object-sync-for-salesforce/pull'; $my_args = array( 'method' => 'POST', 'salesforce_id' => [manually selected id], 'salesforce_object_type' => 'Contact'); wp_remote_post($url, $my_args);…the WP User associated with this SF ID doesn’t update at all? It should show a pull request in the WP-Admin > Users > User [Salesforce] section, right?
Well, I haven’t tested this but I think with the way that
wp_remote_postworks, you’d instead do it like this:$url = 'https://[domain.com]/wp-json/object-sync-for-salesforce/pull'; $data = array( 'salesforce_id' => [manually selected id], 'salesforce_object_type' => 'Contact', ); $response = wp_remote_post( $url, array( 'body' => $data, ) );-
This reply was modified 4 years, 2 months ago by
Jonathan Stegall.
You are absolutely correct, that works! And I have the hook set up functionally now too. Maybe a little bit hacky, but I had to
sleepthepull_this_recordfunction, I assume to give the record a chance to populate into WP after a successful push?Thanks for all your assistance!
Yeah, I think that’s the safest way to do it. The plugin has to do some weirdness when a record is immediately updated to avoid going into an infinite loop, so giving it some time to realize that you want a new update seems wise to me.
-
This reply was modified 4 years, 2 months ago by
The topic ‘Prevent User Object Creation on Sync’ is closed to new replies.