Setting needed to reproduce:

+ A mapping for an item with a set "key" (will trigger an upsert) -- For this example, I'll call this "drupal_contact_has_key"
+ Another mapping for an item with no set "key" (will trigger a normal create/update) -- For this example, I'll call this ""drupal_account_has_no_key"
+ Both mappings have "Process asynchronously" CHECKED.

To replicate:
1) Create a new entity of type "drupal_contact_has_key"
2) Create a new entity of type "drupal_account_has_no_key"
3) Run cron.

Expected result:
Both the "drupal_contact_has_key" and the "drupal_account_has_no_key" items should be created update in Salesforce without error.

Actual result:
No salesforce objects are created and an error is thrown:

Error: WD cron: SoapFault: INVALID_TYPE: all sObjects in create or update must be of same type in SoapClient->__call() (line 519 of     [error]
/Users/mariafisher/Sites/Cascade-Support/public/sites/all/libraries/salesforce/soapclient/SforceBaseClient.php).

Looking at the code, it looks like the problem is in salesforce_push_cron(). Upserts should happen if both $key_field and $key_value evaluate to true:

    // If we have a dedupe key, prefer upsert.
    if ($key_field && $key_value) {
      $upsert_list[$key_field][$delta] = $sobject;
    }
    else {
      // Otherwise create.
      $create_list[$delta] = $sobject;
    }

These values are set by reference earlier:

$params = salesforce_push_map_params($mapping, $wrapper, $key_field, $key_value, $use_soap, !$mapping_object);

However, all this code happens as part of a loop, and the values in $key_field and $key_value are never cleared between loops, either in the salesforce_push_map_params() function or in the loops themselves. This means once they're set, they're set for all items in the queue.

Proposed solution:
Clear out values for $key_field and $key_value with each new loop.

Patch to follow.

Comments

mariacha1 created an issue. See original summary.

mariacha1’s picture

Status: Active » Needs review
StatusFileSize
new595 bytes

Here's that patch.

  • mariacha1 committed 54eafa9 on 7.x-3.x
    Issue #2748067 by mariacha1: Upserting any item during batch processing...
mariacha1’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.