Timestamp dates are not converted correctly

Created on 15 July 2025, 13 days ago

Problem/Motivation

Fields like 'login' on the user entity are stored as timestamps

The SalesforceMappingFieldPluginBase::pushValue() method uses DrupalDateTime($value) passing the timestamp directly but the constructor specifically expects a string. Most dates it works for anyways, but for example "Tue Jul 15 17:52:59 GMT 4679" is returned for the timestamp equivalent of "Tue Jul 15 17:52:59 GMT 2025". Salesforce rejects the year 4679 (but if it didn't it would still be not as expected).

Steps to reproduce

Hard to because not all dates fail conversion

Proposed resolution

Use DrupalDateTime::createFromTimestamp() for timestamps

Remaining tasks

  1. Figure out how to determine whether the source is a timestamp or not
  2. Implement createFromTimestamp() instead

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Workaround

Here is a sample callback for SalesforceEvents::PUSH_PARAMS subscriber to work around this for now.

  public function pushParametersAlter(SalesforcePushParamsEvent $event): void {
    $user = $event->getEntity();
    if (!$user instanceof UserInterface) {
      return;
    }
    $params = $event->getParams();

    // For fields we know are timestamps, create the DrupalDateTime from
    // timestamp specifically instead of via the constructor which expects a string.
    if (
      $params->hasParam('Drupal_Last_Login__c')
      && $timestamp = $user->getLastLoginTime()
    ) {
      $date = DrupalDateTime::createFromTimestamp($timestamp);
      $value = $date->format(\DateTimeInterface::ATOM);
      $params->setParam('Drupal_Last_Login__c', $value);
    }
  }
🐛 Bug report
Status

Active

Version

5.1

Component

salesforce_mapping.module

Created by

🇬🇧United Kingdom scott_euser

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

Comments & Activities

Production build 0.71.5 2024