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
- Figure out how to determine whether the source is a timestamp or not
- 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);
}
}
Comments
Comment #2
vinodhini.e commented