Problem/Motivation

A PHP Fatal error occurs when trying to push data to Salesforce if dealing with a multipickfield.

php.ERROR: TypeError: Argument 2 passed to Drupal\typed_data\DataFetcher::fetchDataBySubPaths() must be of the type array, null given, called in /app/web/modules/contrib/typed_data/src/DataFetcher.php on line 32 in Drupal\typed_data\DataFetcher->fetchDataBySubPaths()

In our case, Salesforce is passing an object to a Typed Data module function which is expecting a string, and Typed Data is attempting to explode that object, which gives us Null which kicks up this error.

(Honestly, I'm not sure if this is a Typed Data issue, or a Salesforce issue.)

Steps to reproduce

If you have a mapping for Drupal ListStringItem fieldtypes to multipickfields in Salesforce. This happens on Push.

This appeared after the core update of 8.9.14... but I can't verify it was actually caused by that.

Proposed resolution

Changing one line in src/Plugin/SalesforceMappingField/PropertiesBase::value seemed to fix this for me. (see CHANGE HERE below)

/**
   * {@inheritdoc}
   */
  public function value(EntityInterface $entity, SalesforceMappingInterface $mapping) {
    // No error checking here. If a property is not defined, it's a
    // configuration bug that needs to be solved elsewhere.
    // Multipicklist is the only target type that handles multi-valued fields.
    $describe = $this
      ->salesforceClient
      ->objectDescribe($mapping->getSalesforceObjectType());
    $field_definition = $describe->getField($this->config('salesforce_field'));
    if ($field_definition['type'] == 'multipicklist') {
      $values = [];
      foreach ($entity->get($this->config('drupal_field_value')) as $value) {
        // CHANGE HERE
        //$values[] = $this->getStringValue($entity, $value);
        $values[] = $this->getStringValue($entity, $value->value);

      }
      return implode(';', $values);
    }
    else {
      return $this->getStringValue($entity, $this->config('drupal_field_value'));
    }
  }

But I feel like I'm missing something, because I can't imagine the method to get the value of a ListStringItem would have changed?

Remaining tasks

User interface changes

API changes

Data model changes

Comments

gregbeat created an issue. See original summary.

gregbeat’s picture

It looks like this change came from the Salesforce 8.x-4.1 to 8.x-4.2 update. I'm not sure if the expectation was that Typed Data should be able to handle this?

aaronbauman’s picture

Can you share the mapping that's giving you this error?
Seems like something is mis-configured.

gregbeat’s picture

Hi Aaron, it's a custom form field (checkboxes) attached to the user profile. Here's an edited (I removed a bunch of other fields) version of the mapping.yml file:

langcode: en
status: true
dependencies:
  config:
    - field.field.user.user.field_hear_about_us
  module:
    - address
    - salesforce_pull
    - salesforce_push
    - token
    - user
id: users
label: Users
weight: 0
type: salesforce_mapping
key: UUID__c
async: false
push_standalone: false
pull_standalone: true
pull_trigger_date: LastModifiedDate
pull_where_clause: ''
sync_triggers:
  push_create: true
  push_update: true
  push_delete: true
  pull_create: false
  pull_update: true
  pull_delete: false
salesforce_object_type: Contact
drupal_entity_type: user
drupal_bundle: user
field_mappings:
  -
    drupal_field_type: properties
    drupal_field_value: field_hear_about_us
    salesforce_field: How_did_you_hear_about_us__c
    direction: sync
    id: 5
push_limit: 0
push_retries: 10
push_frequency: 0
pull_frequency: 0
always_upsert: true

Here's a slightly edited version of the field definition:

<?php
       $form['step4'] = [
          '#type' => 'fieldset',
          '#title' => t('How did you hear about Us?'),
        ];
        $hear_options = [
          'foo' => t('foo'),
          'bar' => t('bar'),
          'other' => t('Other'),
        ];
        $form['step4']['hear_options'] = [
          '#type' => 'checkboxes',
          '#options' => $hear_options,
          '#required' => TRUE,
        ];
?>

Does this help?

aaronbauman’s picture

Version: 8.x-4.2 » 5.0.x-dev
Assigned: Unassigned » aaronbauman
Status: Active » Needs review
StatusFileSize
new7.96 KB

Yeah, looks like a bug.
Here's a test to demonstrate.

I'll see what I can do

Status: Needs review » Needs work

The last submitted patch, 5: salesforce-multipicklist_fail-3211681-5.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

aaronbauman’s picture

Status: Needs work » Needs review
StatusFileSize
new11.42 KB

That test sucked. Here's one that isolates the issue.

Status: Needs review » Needs work

The last submitted patch, 7: salesforce-multipicklist_fail-3211681-7.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

aaronbauman’s picture

Status: Needs work » Needs review
StatusFileSize
new18.33 KB
new18.32 KB

OK, this patch addresses the failing test from #7

use the "4.x" patch for all 8.x-4.x versions.

gregbeat’s picture

#9 Patch for 4.x worked for me!

  • AaronBauman committed 788dfee on 5.0.x
    Issue #3211681 by AaronBauman: Multipick List error getting value
    
  • AaronBauman committed a0147cc on 8.x-4.x
    Issue #3211681 by AaronBauman: Multipick List error getting value
    
tylired’s picture

I'm experiencing this same issue with our website and salesforce mapping. I'll implement this patch, but wanted to find out how this data is supposed to be sent properly to Salesforce for picklists. I'm sending data from a plain text field with values separated by semi-colons.

Example: item1;item2;item3

I want to make sure the problem isn't with how I'm doing things on my side. Thanks for the support.

gcb’s picture

Ran into this error myself and found a slightly simpler fix, which goes nicely with Aaron's tests and is maybe a little more maintainable. Looks like this is already committed but uploading just in case you prefer it @aaron.

These are for 4.x.
multipick_list_error-3211681-13.patch just contains the fix

salesforce-multipicklist_fail-3211681-13-4.x.patch Is the patch along with all the tests and other updates from salesforce-multipicklist_fail-3211681-9-4.x.patch