• Resolved amddtim

    (@amddtim)


    First, really helpful and well-documented plugin so far. Thanks for putting the time in on this!

    I’m attempting to pull somewhere between 20-40 fields from Salesforce into a WordPress custom post type that has corresponding meta fields created with the Advanced Custom Fields plugin. So I’m wondering about two things:

    a) I can map the fields in your plugin backend, but it feels a little tedious. What’s the most efficient way to add all the fields that also lets me easily add and remove fields in the future? I see the object_sync_for_salesforce_pull_params_modify hook, but does it require I know the exact field name from Salesforce?

    b) ACF has it’s own function to save/update meta fields (https://www.advancedcustomfields.com/resources/update_field/). I see that I can change the save function for a mapped item, but 1) ACF’s update_field() function has parameters and I don’t know if your plugin passes parameters when calling the supplied update function, and 2) Even if your plugin used parameters, they are not in the same order, ie, update_field($selector, $value, $post_id) while update_post_meta( $post_id, $meta_key, $meta_value, $prev_value ). Would I need to create my own function to call update_field that reorders the parameters? And where would that function live, in my theme’s functions.php file?

    Thanks for the help!

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

    (@jonathanstegall)

    @amddtim the only custom field support this plugin officially provides is what WordPress has out of the box, so it’s possible that ACF will have issues. That being said, you certainly can map ACF fields with this plugin.

    To your questions:

    A) The object_sync_for_salesforce_pull_params_modify hook is designed to change field values, for example. You could try using it in the way you describe, but it certainly isn’t meant to do that and it might have unforeseen consequences. Also you would certainly have to know the API field name of the Salesforce field. I would encourage you to map the fields in the interface instead, I think.

    I could see it being tedious with lots and lots of fields, but hopefully it isn’t the kind of thing you have to do too often.

    Also we would certainly review GitHub pull requests if you think there are better ways to design the form for larger field numbers.

    B) That is true. Currently, the method hook does not change the order of parameters. It passes them like method( $id, $key, $value ). You could make your own function as you say, but what I’ve observed is that at least in the case of ACF, you can just let the plugin treat it as a normal WordPress meta field.

    As long as you map the ACF field that does not have the underscore in front of it, you should be fine. For example I have a test install that maps test_field to Contact_description. The fieldmap screen also shows has a _test_field in the dropdown because of how ACF works in its non-WordPress way, but I’ve found that I can safely ignore that one and it will work fine in both push and pull.

    Thread Starter amddtim

    (@amddtim)

    Thanks for the quick reply.

    Yeah, I have mapped some ACF fields and saw at least half success. The thing that worried me is that normally saving an ACF field in the backend also creates a corresponding underscored field with the ACF field_key. It seems like that would be integral to ACF, which is why I wanted to go the update_field() route.

    I guess I’ll try adding my own function, like reorder_params_update_field(). Remind me which hook would be the best place to add that function for each mapped field…?

    Plugin Author Jonathan Stegall

    (@jonathanstegall)

    @amddtim I don’t have a ton of experience using ACF, but in all of my testing with this plugin it creates the underscore field every time it’s supposed to, even if I only map the field without the underscore. I expect it has its own hooks that run. I would encourage you to try it that way and see if it works as you expect.

    The only thing I would say is that this plugin is unaware of meta fields until there is at least one record that has a value for it. So if you added an ACF field called “foo” to the user object, you’d have to have at least one user with a value for the foo field before it would show up in the fieldmap options. This is because there’s no consistent way of getting a list of meta fields before they have values.

    But in any case, the hook that you’d want to use is object_sync_for_salesforce_pull_params_modify. There’s some documentation about it here: https://github.com/MinnPost/object-sync-for-salesforce/blob/master/docs/extending-parameters.md#salesforce-pull. I do think you won’t need it, since ACF seems to take care of the underscore field on its own, but it’s there if you do.

    Plugin Author Jonathan Stegall

    (@jonathanstegall)

    @amddtim were you able to resolve this yet?

    Thread Starter amddtim

    (@amddtim)

    Marking this as resolved, even though I’d still love to see ACF support in the future. Thanks for the assistance!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Pull from Salesforce to WordPress ACF Fields’ is closed to new replies.