Mapped date fields are not properly syncing data.

Created on 25 March 2020, almost 5 years ago
Updated 31 January 2024, 11 months ago

Problem/Motivation

I came across this issue while syncing User Last Login data with Salesforce.

This issue is applicable on Salesforce 8.x-4.x and 8.x-3.x.

There are essentially 3 problems.

Case: date/datetime is 0

Code that is run

$date = new DrupalDateTime('0', 'UTC');
$value = $date->format(DateTime::ISO8601);

$value is '' and this may runs into validation errors in Salesforce.
[{"message":"Cannot deserialize instance of date from VALUE_STRING value or request may be missing a required field at [line:1, column:373]","errorCode":"JSON_PARSER_ERROR"}]

Case: date/datetime is empty or ''

Code that is run

$date = new DrupalDateTime('', 'UTC');
$value = $date->format(DateTime::ISO8601);

$value is the current timestamp ('now') and this is incorrect data.

Case: date/datetime is a timestamp

Code that is run

$date = new DrupalDateTime('1585167349', 'UTC');
$value = $date->format(DateTime::ISO8601);

You cannont create a DateTime object from a timestamp this way.
This results in a bad Date object and Salesforce returns the following error.
[{"message":"Cannot deserialize instance of date from VALUE_STRING value or request may be missing a required field at [line:1, column:373]","errorCode":"JSON_PARSER_ERROR"}]

Proposed resolution

I am adding 3 things.
* Handle cases where the field is a timestamp field
* Handle cases where the date value is a timestamp (if it was not a timestamp field)
* Handle cases where the date value is empty() (returns NULL)
* Hanlde any outside cases (returns NULL)

Addendum:
* Handle 0, 0.0, and '0' date values as timestamps instead of emtpy values

πŸ› Bug report
Status

Closed: outdated

Version

4.0

Component

salesforce_mapping.module

Created by

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States AaronBauman Philadelphia

    I'm doing some cleanup on unsupported branches.
    Please re-open this issue and update the version to 5.0.x-dev if this issue is still applicable to the latest release.

Production build 0.71.5 2024