Problem/Motivation
I need a way to act immediately after a Drupal entity has been saved as part of a Salesforce Pull operation. In this hook I need access to both the Salesforce object and the saved Drupal entity.
Utilizing hook_entity_insert() and hook_entity_update() isn't a solution here because by that time I've lost access to the Salesforce object.
My use case here is creating/updating a referencing (parent) entity with data from the Salesforce object. This is not a simple relationship that can be mapped in the mapping interface.
Proposed resolution
Add a hook that will allow modules to respond to an entity being saved in a Salesforce pull.
Remaining tasks
Patch needs to be reviewed and tested by the community (RTBC).
Please review salesforce-Add-hook_salesforce_pull_entity_save-2650502-0.patch. It has been rolled off of 7.x-3.x.
The salesforce-Add-hook_salesforce_pull_entity_save-2650502-0-against-stable-3-1.patch patch file is only here for those who want to patch the stable 7.x-3.1 release.
User interface changes
None.
API changes
Addition of hook_salesforce_pull_entity_save() in salesforce.api.php.
/**
* Allow modules to respond to an entity being saved in a Salesforce pull.
*
* @param object $sf_object
* The fully-loaded Salesforce object.
* @param string $entity_type
* The Drupal entity type.
* @param object $entity
* The Drupal entity that was just saved.
*/
Data model changes
None.
Comments
Comment #2
aaronbaumanI think #2223669: Add "pull allowed" hooks covers this use case.Please re-open if you disagree.
Comment #3
aaronbaumanSorry, wrong issue.
Please followup on discussion in #2186153: Provide additional Salesforce push/pull hooks for pre_export changes.
Comment #4
chrisolofAdding patch against 7.x-3.x
Comment #5
chrisolof@aaronbauman See my comment in #2186153: Provide additional Salesforce push/pull hooks for pre_export changes..
Comment #6
chrisolofAdding a patch against the stable 3.1 release for use by those who need this hook but aren't able or willing to run 7.x-3.x-dev. Please use salesforce-Add-hook_salesforce_pull_entity_save-2650502-0.patch for any reviewing/testing against 7.x-3.x.
Comment #7
chrisolof#2688033: Add entity_presave/insert/update sf pull hooks resolves this issue by including entity update and insert hooks. In my opinion it's the better route and more closely follows core's model for these types of hooks.