How to pull a record from Salesforce and immediately push the node ID back to Salesforce I'm using the Salesforce Suite module.

What I'm trying to accomplish:

When a record is created in Salesforce, that record is pulled into Drupal and the new node content ID is pushed back to the Salesforce record (for reference in Salesforce).

I have a mapping set up as such:

Triggers


Drupal create (push)
Drupal update (push)
Salesforce create (pull)
Salesforce update (pull)


Fields


Title - Salesforce to Drupal
Content ID - Drupal to Salesforce


With this setup, it pulls the record into Drupal but the Content ID doesn't get pushed back to Salesforce. It will, however push when I update (just save) the node but we don't expect these nodes to be saved anytime soon after it's pulled in.

I've tried a few different ways leveraging the events dispatched by the Salesforce module but it always leads me to a race condition or a circle.
Here's how I did it...

Since content is set to push (immediately) on update, I added a hook_entity_insert() that responded not to the content insert but the "salesforce_mapped_object" entity.

This ensures that not only was the node/user created but a mapping was created.

/**
 * Implements hook_entity_insert().
 */
function MYMODULE_entity_insert(Drupal\Core\Entity\EntityInterface $entity) {
  if ($entity-&gt;bundle() == 'salesforce_mapped_object') {
    $entity_info = $entity-&gt;get('drupal_entity')-&gt;first()-&gt;getValue();
    $type = $entity_info['target_type'];
    $id = $entity_info['target_id'];
    switch ($type) {
      case 'node':
        $node = \Drupal\node\Entity\Node::load($id);
        $node-&gt;save();
        break;
      case 'user':
        $user = \Drupal\user\Entity\User::load($id);
        $user-&gt;save();
        break;
    }
  }
}


Thanks to @leymannx in the above comment for the guidance.