• Resolved Insight Dezign

    (@insightdezign)


    I’m using the plugin to sync Salesforce accounts to a WordPress custom post type. When I edit an account in Salesforce it will create a draft post in WordPress and the Log shows no issue. When I change the post from Draft to Published it creates a new Salesforce account rather than syncing back to the existing. What am I doing wrong?

    Also, I would like these to be published not drafts when they come in.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter Insight Dezign

    (@insightdezign)

    I’m experimenting with this and adding additional info.

    Based on the information you provided on Prematch, I created a custom meta field for salesforce ID. I’m mapping that to the Salesforce Account ID, have it set for Prematch and Sync. When I edit an account in Salesforce that doesn’t exist in WordPress it upserts a new draft post. When I publish it or change anything on it in WordPress is upserts and corrects the Salesforce record. However, when I edit the Salesforce record it then creates a new draft post in WordPress. What does the plugin use for a matching key for records?

    Thread Starter Insight Dezign

    (@insightdezign)

    Just checked the php error log and I’m getting a bunch of these with different wordpress ID’s.

    [22-Jan-2019 00:09:46 UTC] WordPress database error Table ‘musican2_carecomm.mus_object_sync_sf_object_map’ doesn’t exist for query SELECT * FROM mus_object_sync_sf_object_map WHERE wordpress_id = “6312” AND wordpress_object = “scheduled-action” ORDER BY object_updated, created made by do_action_ref_array, WP_Hook->do_action, WP_Hook->apply_filters, ActionScheduler_QueueRunner->run, ActionScheduler_QueueRunner->do_batch, ActionScheduler_Abstract_QueueRunner->process_action, ActionScheduler_Abstract_QueueRunner->schedule_next_instance, ActionScheduler_wpPostStore->save_action, ActionScheduler_wpPostStore->save_post_array, wp_insert_post, do_action(‘save_post’), WP_Hook->do_action, WP_Hook->apply_filters, Object_Sync_Sf_Salesforce_Push->post_actions, Object_Sync_Sf_Salesforce_Push->object_insert, Object_Sync_Sf_Salesforce_Push->salesforce_push_object_crud, Object_Sync_Sf_Mapping->load_by_wordpress, Object_Sync_Sf_Mapping->get_object_maps

    Plugin Author Jonathan Stegall

    (@jonathanstegall)

    If I’m understanding you correctly, your install of the plugin is missing a required table: _object_sync_sf_object_map (starting with whatever your prefix is). The plugin is unable to connect records to each other without this table.

    Usually, this table gets added when the plugin is installed, but there are some hosts that seem to have trouble with it. It’s unclear why, and I’ve never been able to reproduce it myself.

    But to fix it, if you have access to your database, you can create the table with the following SQL. You’ll want to replace wp_ in the table name with whatever your install prefix is, if it’s not wp_:

    CREATE TABLE wp_object_sync_sf_object_map (
      id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
      wordpress_id varchar(32) COLLATE utf8mb4_unicode_520_ci NOT NULL,
      salesforce_id varbinary(32) NOT NULL DEFAULT '',
      wordpress_object varchar(128) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT '',
      created datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
      object_updated datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
      last_sync datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
      last_sync_action varchar(128) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
      last_sync_status tinyint(1) NOT NULL DEFAULT '0',
      last_sync_message varchar(255) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
      PRIMARY KEY (id),
      UNIQUE KEY salesforce (salesforce_id),
      UNIQUE KEY salesforce_wordpress (wordpress_object,wordpress_id),
      KEY wordpress_object (wordpress_object,wordpress_id),
      KEY salesforce_object (salesforce_id)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;

    I’m assuming your install process was able to create the field map table, but in case it was not, this is the SQL for that table:

    CREATE TABLE wp_object_sync_sf_field_map (
      id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
      label varchar(64) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT '',
      name varchar(64) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT '',
      wordpress_object varchar(128) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT '',
      salesforce_object varchar(255) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT '',
      salesforce_record_types_allowed longblob,
      salesforce_record_type_default varchar(255) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT '',
      fields longtext COLLATE utf8mb4_unicode_520_ci NOT NULL,
      pull_trigger_field varchar(128) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT 'LastModifiedDate',
      sync_triggers text COLLATE utf8mb4_unicode_520_ci NOT NULL,
      push_async tinyint(1) NOT NULL DEFAULT '0',
      push_drafts tinyint(1) NOT NULL DEFAULT '0',
      weight tinyint(1) NOT NULL DEFAULT '0',
      version varchar(255) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT '',
      pull_to_drafts tinyint(1) NOT NULL DEFAULT '0',
      PRIMARY KEY (id),
      UNIQUE KEY name (name),
      KEY name_sf_type_wordpress_type (wordpress_object,salesforce_object(191))
    ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;

    You’ll probably want to deactivate and reactivate the plugin, since there are some things it is supposed to do after it creates the tables.

    Finally, if you want the post to be published instead of a draft when it arrives from Salesforce, you can do this in two ways:

    1. Create a field in Salesforce that has a value of ‘publish’ and map it to the post_status field in WordPress
    2. Use a developer hook to set the value of the post_status field. It would be something like this:
      add_filter( 'object_sync_for_salesforce_pull_params_modify', 'change_pull_params', 10, 6 );
      function change_pull_params( $params, $mapping, $object, $sf_sync_trigger, $use_soap, $is_new ) {
      	$params['post_status'] = 'publish';
      	return $params;
      }
    Thread Starter Insight Dezign

    (@insightdezign)

    When I tried to create the table the first time I got the following error.

    #1273 – Unknown collation: ‘utf8mb4_unicode_520_ci’

    Then I changed the collation type and tried again and got the following error.

    #1067 – Invalid default value for ‘created’

    After following a few different topics, I found the problem is because I have MySQL 5.5.

    https://stackoverflow.com/questions/23153822/mysql-datetime-default-current-timestamp-error

    I’m working on upgrading MySQL, unless you know of another way?

    Thread Starter Insight Dezign

    (@insightdezign)

    I updated the database and was able to create the table, but now I’m getting the following PHP errors.

    [22-Jan-2019 23:13:44 UTC] PHP Warning: Illegal string offset ‘method_modify’ in /home/musican2/mydomain.com/wp-content/plugins/object-sync-for-salesforce/classes/wordpress.php on line 1164
    [22-Jan-2019 23:13:44 UTC] PHP Warning: Illegal string offset ‘method_modify’ in /home/musican2/mydomain.com/wp-content/plugins/object-sync-for-salesforce/classes/wordpress.php on line 1200
    [22-Jan-2019 23:13:44 UTC] PHP Fatal error: Uncaught Error: Call to undefined function p() in /home/mmydomain.com/wp-content/plugins/object-sync-for-salesforce/classes/wordpress.php:1201

    Plugin Author Jonathan Stegall

    (@jonathanstegall)

    I’m going to investigate this last error further. It’s happening because of the object_sync_for_salesforce_pull_params_modify hook you’re using; it’s possible that method has a bug that didn’t previously exist. If so, I’ll try to release a fix shortly.

    But in the meantime, you can remove that hook usage and instead create a field in Salesforce that has a value of ‘publish’ and map it to the post_status field in WordPress.

    Plugin Author Jonathan Stegall

    (@jonathanstegall)

    Apparently I had the wrong syntax for my own hook. See the documentation here.

    This hook should instead work like this:

    add_filter( 'object_sync_for_salesforce_pull_params_modify', 'change_pull_params', 10, 6 );
    function change_pull_params( $params, $mapping, $object, $sf_sync_trigger, $use_soap, $is_new ) {
    	$params['post_status'] = array ( // wordpress field name
    		'value' => 'publish',
    		'method_modify' => 'wp_update_post',
    		'method_read' => 'get_posts'
    	);
    	return $params;
    }

    I’ve tested this and it does create new posts with published status.

    • This reply was modified 6 years, 2 months ago by Jonathan Stegall. Reason: clarify that in this particular case you have to add a new parameter rather than replacing the params array. also fix code formatting
    Plugin Author Jonathan Stegall

    (@jonathanstegall)

    I updated to reflect how you’d use the syntax in this particular case.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Draft to Publish Issue’ is closed to new replies.