Skip to content

Instantly share code, notes, and snippets.

@jonathanstegall
Last active September 22, 2021 16:11
Show Gist options
  • Select an option

  • Save jonathanstegall/afef1e44e27ab817eed7d9f5ab674d83 to your computer and use it in GitHub Desktop.

Select an option

Save jonathanstegall/afef1e44e27ab817eed7d9f5ab674d83 to your computer and use it in GitHub Desktop.
<?php
add_action( 'object_sync_for_salesforce_push_success', 'save_sf_id_acf', 10, 5 );
function save_sf_id_acf( $op, $response, $synced_object, $object_id, $wordpress_id_field_name ) {
// do things if the save succeeded
// $op is what the plugin did - Create, Update, Upsert, Delete
// $response is what was returned by the $salesforce class. sfapi->response
// $synced_object is an array like this:
/*
$synced_object = array(
'wordpress_object' => $object,
'mapping_object' => $mapping_object,
'queue_item' => false,
'mapping' => $mapping,
);
*/
// you might want to exit out if it's not a newly created record, like this:
if ( 'Create' !== $op ) {
return;
}
// $object_id is the salesforce object id
// $wordpress_id_field_name is the name of the ID field in WordPress
// so the WP post ID would be stored in $synced_object['wordpress_object'][ $wordpress_id_field_name ]
$post_id = $synced_object['wordpress_object'][ $wordpress_id_field_name ];
// you would need to figure out what $field_name should be using somehow
update_field( $field_name, $object_id, $post_id ); // this is an ACF method
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment