Enhancement to Salesforce Cron Logic to Support Custom Node Update Handling

Created on 27 June 2024, 6 months ago
Updated 16 July 2024, 5 months ago

Problem/Motivation

I have customized the Salesforce module implementation of mapped object operations and pushing to salesforce queue on node update.
To achieve this, I disabled the "push_update" parameter of the relevant Salesforce mapping and implemented my own hook_node_update in a custom module to push only when certain conditions are met.

However, the Salesforce cron does not run when I push from my custom code because the cron logic relies on the doesPush() method, which checks for sync triggers. Since no action trigger parameters are selected, the cron is blocked and does not execute as expected.
Same problem when intenting to push with drush command drush salesforce_push:push-queue (calls getPushMappingsFromName which depends also on Salesforce mapping doesPush() method)

Steps to reproduce

1. Disable the "push_update" parameter in the Salesforce mapping.
2. Implement a custom hook_node_update to handle Salesforce pushes conditionally.
3. Perform a node update that should trigger a Salesforce push.
4. Observe that the Salesforce cron does not run due to the doesPush() method logic blocking it.
5. Observe that drush salesforce_push:push-queue doesn't work as expected

Proposed resolution

1. **Bypassing Trigger Checks:**
- Add an optional parameter to the doesPush() method to ignore the trigger check:

     public function doesPush($ignore_triggers = FALSE) {
       if ($ignore_triggers) {
         return TRUE;
       }
       return $this->checkTriggers([
         MappingConstants::SALESFORCE_MAPPING_SYNC_DRUPAL_CREATE,
         MappingConstants::SALESFORCE_MAPPING_SYNC_DRUPAL_UPDATE,
         MappingConstants::SALESFORCE_MAPPING_SYNC_DRUPAL_DELETE,
       ]);
     }

- This allows custom code to force the Salesforce cron to run when necessary while preserving the current logic for standard cases.

2. **Reevaluating the Necessity of doesPush():
- Reassess whether the doesPush() method is necessary and in which specific context.

API changes

Potential changes to the doesPush() method in the Salesforce module:
- Adding an optional parameter to allow bypassing trigger checks (?)

✨ Feature request
Status

Active

Version

5.1

Component

salesforce_mapping.module

Created by

πŸ‡«πŸ‡·France federiko_

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024