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?
Comments
Comment #2
gregbeat commentedIt 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?
Comment #3
aaronbaumanCan you share the mapping that's giving you this error?
Seems like something is mis-configured.
Comment #4
gregbeat commentedHi 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:
Here's a slightly edited version of the field definition:
Does this help?
Comment #5
aaronbaumanYeah, looks like a bug.
Here's a test to demonstrate.
I'll see what I can do
Comment #7
aaronbaumanThat test sucked. Here's one that isolates the issue.
Comment #9
aaronbaumanOK, this patch addresses the failing test from #7
use the "4.x" patch for all 8.x-4.x versions.
Comment #10
gregbeat commented#9 Patch for 4.x worked for me!
Comment #12
tylired commentedI'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.
Comment #13
gcbRan 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