Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Jonathan Stegall

    (@jonathanstegall)

    Yes. Look into this filter, object_sync_for_salesforce_pull_object_allowed.

    Thread Starter thomasazar

    (@thomasazar)

    Thanks @jonathanstegall for the quick reply! I am no developer but willing to give it my best go. I have updated the filter with the intention of pulling all contacts where the custom field “Contact_s_MembershipsList_aa__c” contains “NTL – Civil Plaintiff – Top 100” then pull those contacts. I updated the filter on ‘salesforce-pull.php to be as…

    add_filter( ‘object_sync_for_salesforce_pull_object_allowed’, ‘check_user’, 10, 5 );
    // can always reduce this number if all the arguments are not necessary
    function check_user( $pull_allowed, $object_type, $object, $sf_sync_trigger, $salesforce_mapping ) {
    if ( $object_type === ‘Contact’ && $object[‘Contact_s_MembershipsList_aa__c’] === ‘NTL – Civil Plaintiff – Top 100’ ) {
    $pull_allowed = true;
    }
    return $pull_allowed;
    }

    Do you see any issues with this?

    • This reply was modified 4 years, 1 month ago by thomasazar.
    Thread Starter thomasazar

    (@thomasazar)

    After getting it all setup I am getting closer…

    i set the data field to “last modified date”

    Set it to run 1 every 60 minutes. Manually ran it also. But it just says 1 in queue.

    Any suggestions on what to do next?

    Thread Starter thomasazar

    (@thomasazar)

    We are trying to sync members within salesforce to wordpress. Because we have multiple contacts and memberships in salesforce we need to filter on these.

    We created a custom post type and are wanting to pull these members in as a post to be used for a directory.

    We also need to pull existing members and periodically check for new members to push to wordpress. At this time no data will be needed to push to sf.

    Looking for assistance with this and would like to hire someone to help get this accomplished. Please let me know if interested or have any suggestions of someone that can help. Thanks!

    Plugin Author Jonathan Stegall

    (@jonathanstegall)

    I’m not currently available for this, but certainly many WordPress developers should be able to accomplish this.

    Thread Starter thomasazar

    (@thomasazar)

    Thanks @jonathanstegall for your help. I believe we are getting close but I do have one more question…
    When syncing this way and a member becomes inactive the hook will no longer sync with records. But how do we delete the custom post for that member that was created automatically?

    Plugin Author Jonathan Stegall

    (@jonathanstegall)

    The way your function works is that it tells the plugin to only process records that meet the criteria you have specified. So in other words, the records that are no longer syncing are ignored by this plugin.

    To delete a record that isn’t being processed from WordPress, it’s a bit more complicated. You’d have to write some code to find the object ID in WordPress, and then delete it.

    This is a basic example that might work. The process here is:

    1. Check for a Salesforce contact with the last name of “deleteme”
    2. Get the WordPress user ID that it’s mapped to
    3. Delete that WordPress user
    4. Don’t let this plugin do any more processing on that user (this is still important since otherwise it would raise an error.

    I’m not sure if the forum will handle this code formatting super well, so I’ve also added it to a GitHub gist. You’d obviously want to do a lot of testing with this before using it, with a test site/sandbox, to make sure it does what you want it to do.

    add_filter( 'object_sync_for_salesforce_pull_object_allowed', 'process_user', 10, 5 );
    function process_user( $pull_allowed, $object_type, $object, $sf_sync_trigger, $salesforce_mapping ) {
    	if ( 'Contact' === $object_type && 'deleteme' === $object['LastName'] ) {
    		$pull_allowed = false;
    		if ( ! function_exists( 'is_plugin_active' ) ) {
    			require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
    		}
    		if ( is_plugin_active( 'object-sync-for-salesforce/object-sync-for-salesforce.php' ) ) {
    			$salesforce     = Object_Sync_Salesforce::get_instance();
    			$mapping_object = $salesforce->mappings->get_object_maps(
    				array(
    					'salesforce_id' => $object['Id'],
    				)
    			);
    			$wordpress_id   = $mapping_object['wordpress_id'];
    			$wordpress_type = $mapping_object['wordpress_object'];
    			$delete_user    = wp_delete_user( $wordpress_id );
    		}
    	}
    	return $pull_allowed;
    }
    Plugin Author Jonathan Stegall

    (@jonathanstegall)

    Hopefully you were able to get what you need from this. I’m going to mark this as resolved.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Pull from Salesforce and filter’ is closed to new replies.