Question:
While reading timestamp data from Salesforce using Salesforce connection, time zone is getting converted to target system's time zone automatically. How to preserve the source time zone? Also, during preview it is showing the client time zone.
For example, you may have a timestamp data (timestamp along with timezone) in Salesforce present in GMT and target system (say, Kafka) in EST. So, when data is moved, it is getting changed to EST automatically at Kafka end.
Answer:
Timestamps are read from Salesforce in UTC (same as GMT). From then on, it is processed just like any other data in SDC. Timestamps are shown in preview in the local time zone - this can be configured in console settings. Setting console to UTC timezone will show that Salesforce timestamps are correct.
Writing timestamps to target systems is dependent on target system settings. If the timestamp does not carry timezone information, the target system will often assume it is in the local timezone. Converting the timestamp to a string and ensuring it carries timezone information - for example, yyyy-MM-dd'T'HH:mm:ss.SSS Z is often useful when writing to a target system.
The following Expression Evaluator can be used to convert each timestamp to the correct time zone. For example:
Output Field: /CreatedDate
Field Expression: ${time:extractStringFromDateTZ(record:value('/CreatedDate'), "GMT", "EEE MMM dd HH:mm:ss z yyyy")}
Do note that the Salesforce API returns timestamps in UTC with no indication of the actual timezone in use within the Salesforce org. Hence we have to explicitly indicate the desired timezone, as in the above example.