Title: Can&#8217;t map multiple WordPress objects to the same Salesforce object
Last modified: January 18, 2018

---

# Can’t map multiple WordPress objects to the same Salesforce object

 *  Resolved [joecanas1](https://wordpress.org/support/users/joecanas1/)
 * (@joecanas1)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/cant-map-multiple-wordpress-objects-to-the-same-salesforce-object/)
 * The unique key constraint on salesforce_id in the object_map table prevents mapping
   more than one WordPress object (e.g., user, shop_order) to the same Salesforce
   object (e.g., Contact). I need this functionality so I can update SF Contact 
   records with data stored in two different WP objects. What are the ramifications
   of removing that unique key constraint — or would it require extensive customization
   to achieve what I describe below?
 * SF Contacts are initially created outside of the OSfS plugin (using Zapier webhooks).
   The Contact record contains a field with WordPress ID (populated with the corresponding
   WP user ID when created).
 * Fieldmaps:
 * 1. Sync WP user addresses with corresponding SF Contact mailing addresses:
 * WP object: user
    SF object: Contact Trigger on WP or SF update, sync both directions
   Prematch: WP user.ID : SF WordPress ID.
 * 2. Push the shipment tracking number for a customer order (stored in the ‘shop_order’
   custom post’s meta data) to the corresponding SF Contact record.
 * WP object: shop_order
    SF object: Contact Trigger on WP update, sync WP-to-SF
   only Prematch: WP ‘_customer_user’ postmeta field (same as user ID) : SF WordPress
   ID
 * Each fieldmap works as expected when running alone. But the unique key constraint
   on salesforce_id prevents both fieldmaps from working together — only one mapping
   can be stored and subsequently executed.
 * I didn’t see this restriction mentioned in the documentation (though it’s clear
   from looking at the schema). Moreover, the Fieldmaps tab’s ‘Weight’ section says:‘
   Weight is intended for use when you have multiple fieldmaps for the same object,
   either in WordPress or Salesforce.’
 * Many thanks for the great (and well documented) plugin, and for any guidance 
   you can provide.

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Author [Jonathan Stegall](https://wordpress.org/support/users/jonathanstegall/)
 * (@jonathanstegall)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/cant-map-multiple-wordpress-objects-to-the-same-salesforce-object/#post-9879400)
 * [@joecanas1](https://wordpress.org/support/users/joecanas1/) you’re right, that
   weight field is misleading. I need to think more about this and determine what
   we were doing with this field. It’s possible it should go away, or that it needs
   some significant work to behave as expected. I’m just not sure at the moment.
 * However, I think it’s possible you could accomplish your goal with existing developer
   hooks in the plugin. I am not particularly familiar with WooCommerce or how its
   API works (although I know it has one), so it may be naive of me, but here’s 
   the kind of thing you could investigate:
 *     ```
       add_filter( 'object_sync_for_salesforce_push_params_modify', change_push_params', 10, 6 );
       function change_push_params( $params, $mapping, $object, $sf_sync_trigger, $use_soap, $is_new ) {
   
       	/*
       	if woocommerce provides a way to get the shipment tracking number via its api, with any data that you have available at this point, you could retrieve it
       	* if the operation is an update ($is_new = false), the Salesforce object ID is also there. I don't think it would be ideal, but you could access the plugin's instance of the Salesforce API here as well and query it.
       	*
       	if ( is_object( $this->salesforce ) ) {
       		$salesforce_api = $this->salesforce->salesforce['sfapi'];
       	} else {
       		$salesforce = $this->salesforce();
       		$salesforce_api = $salesforce->salesforce['sfapi'];
       	}
   
       	if ( is_object( $salesforce_api ) ) {
       		$query = "you can write any SOQL query that works in Salesforce here, and get results back";
       		$result = $salesforce_api->query( $query );
       	}
       	*/
       	$shipment_tracking_number = 'something';
   
           $params = array(
               'email' => 'test@test.com',
               'FirstName' => 'test',
               'LastName' => 'name'
               'ShipmentTrackingNumber__c' => $shipment_tracking_number,
           );
           return $params;
       }
       ```
   
 *  Thread Starter [joecanas1](https://wordpress.org/support/users/joecanas1/)
 * (@joecanas1)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/cant-map-multiple-wordpress-objects-to-the-same-salesforce-object/#post-9879531)
 * Thanks for the speedy response and excellent idea. I was also counting on the
   separate fieldmap trigger on shop_order (vs. user) updates. With the approach
   you described, I’d only have the WP user object’s update action available as 
   a trigger.
 * In practice, the tracking number will be manually added to some (not all) orders
   some time after the order is created (i.e., once the order ships via USPS and
   a tracking number is issued). Unless the WP user record tied to the order is 
   also updated, the tracking number might never be pushed to SF.
 * There’s probably a way to handle just the tracking number update using the plugin’s
   SF API object outside of standard fieldmap/trigger behavior, but I was of course
   hoping to avoid a large amount of custom coding.
 * If you determine that the salesforce_id field must remain unique, perhaps the
   Fieldmaps creation workflow could be modified to detect and prevent additional
   mappings to a previously mapped SF object. (At a minimum, remove it from the 
   select list if it was used in an earlier fieldmap.)
 *  Plugin Author [Jonathan Stegall](https://wordpress.org/support/users/jonathanstegall/)
 * (@jonathanstegall)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/cant-map-multiple-wordpress-objects-to-the-same-salesforce-object/#post-9890872)
 * [@joecanas1](https://wordpress.org/support/users/joecanas1/) I think there’s 
   a fairly large amount of work that will need to be done to provide the ability
   to sync multiple objects to the same object like this. I think it is a good feature
   if it can be done properly, but it’s a good bit of work and may prove complicated.
 * I think what I’ll do is hide this weight field in the next small release of the
   plugin, as you are completely right that it is misleading. We can reveal it again
   when/if the functionality is working as it should.
 * I’ve added a GitHub issue to track this here: [https://github.com/MinnPost/object-sync-for-salesforce/issues/135](https://github.com/MinnPost/object-sync-for-salesforce/issues/135)
 * I’ll leave it up to you whether it is good to close this topic for now, but I
   don’t think we’ll have an immediate solution.
 *  Thread Starter [joecanas1](https://wordpress.org/support/users/joecanas1/)
 * (@joecanas1)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/cant-map-multiple-wordpress-objects-to-the-same-salesforce-object/#post-9891851)
 * Thanks for considering this as a future enhancement. I may try coding a workaround
   for the scenario I described: use the plugin to manage the bi-directional multi-
   field address sync, and call the SF API for a custom one-time WP-to-SF only push
   of the order tracking number to the SF contact record.
 *  Thread Starter [joecanas1](https://wordpress.org/support/users/joecanas1/)
 * (@joecanas1)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/cant-map-multiple-wordpress-objects-to-the-same-salesforce-object/#post-9891852)
 * And yes, good to close this topic for now.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Can’t map multiple WordPress objects to the same Salesforce object’ is
closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/object-sync-for-salesforce.svg)
 * [Object Sync for Salesforce](https://wordpress.org/plugins/object-sync-for-salesforce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/object-sync-for-salesforce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/object-sync-for-salesforce/)
 * [Active Topics](https://wordpress.org/support/plugin/object-sync-for-salesforce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/object-sync-for-salesforce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/object-sync-for-salesforce/reviews/)

 * 5 replies
 * 2 participants
 * Last reply from: [joecanas1](https://wordpress.org/support/users/joecanas1/)
 * Last activity: [8 years, 4 months ago](https://wordpress.org/support/topic/cant-map-multiple-wordpress-objects-to-the-same-salesforce-object/#post-9891852)
 * Status: resolved