Ran into a bit of an issue when I was trying to map SF fields to an addressField. After some review, it looks like as the entity is being updated with values from salesforce, the array representing the address field is being destroyed. Essentially, the last mapped piece of the address field is the only mapping that sticks.

Also, field values in the entity are being mapped with 'value' instead of using '$column'.

The following code worked for me...changes are noted in comments below. My mappings are working now.

Appreciate the module, btw!


function sf_entity_import_field_default(&$entity, $fieldkey, $drupal_field_definition, $sf_data, $sf_fieldname, $sf_field_definition) {

  $lang = _sf_entity_get_language($entity);
  
  // Get the data array for the field.
  list($fieldname, $column) = explode(':', $fieldkey, 2);
  if (empty($column)) {
    $column = 'value';
  }
  
  $data = $entity->$fieldname;   ///////// ADD THIS LINE, IT WAS MISSING ////////////
  
  // Don't try to do an import for a field that does't exist in the response from Salesforce.
  if(!isset($sf_data->$sf_fieldname)) {
    return;
  }

  // Convert data based on what Salesforce type we're importing.
  // @todo: Also does conversions based on what types (checkbox, date field) it is assumed are being used
  // to map them in Drupal. Later, change that to be a separate case statement based on field_info_field().
  switch ($sf_field_definition['salesforce']['type']) {
    case 'multipicklist':
      // Salesforce sends multiple values as a semicolon-delimited string.
      // @todo: Determine how the field definition for multi-valued fields in Drupal is being set.
      if (isset($drupal_field_definition['multiple'])) {
        $sf_data = explode(';', $sf_data->$sf_fieldname);
        foreach ($sf_data as $row) {
          $data[$lang][] = array('value' => $row);
        }
      }
      else {
        $data[$lang][0][$column] = $sf_data->$sf_fieldname;
      }
      break;
    case 'boolean':
      // Drupal stores boolean fields as ints.
      // Trying to pass a boolean value (TRUE, FALSE) will cause a fatal database error.
      $data[$lang][0][$column] = (int) $sf_data->$sf_fieldname; ///////$COLUMN INSTEAD OF 'VALUE' /////////
      break;
    case 'date':
    case 'datetime':
      // Truncate the date to a length that can be saved.
      $data[$lang][0][$column] = substr($sf_data->$sf_fieldname, 0, 19);  ///////$COLUMN INSTEAD OF 'VALUE' /////////
      break;
    default:
      // Unless handled above in this switch, we don't yet handle fields with multiple values.
      $data[$lang][0][$column] = $sf_data->$sf_fieldname;    ///////$COLUMN INSTEAD OF 'VALUE' /////////
    break;
  }
   

  $entity->$fieldname = $data;// Populates the value of a Field API field from its corresponding Salesforce field's value.

}

CommentFileSizeAuthor
#1 compoundfieldimport-1706906.patch1.57 KBtimozura

Comments

timozura’s picture

StatusFileSize
new1.57 KB

patch submitted for consideration

kostajh’s picture

Status: Active » Needs review
aaronbauman’s picture

Component: sf_entity » Code
Status: Needs review » Fixed

committed ad5251ad

Status: Fixed » Closed (fixed)

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