0

I have some basic questions about the date/time fields in Salesforce. I know Salesforce stores the date and time fields in GMT format in the object when a record is created or updated and also retrieves them in GMT format when a record is queried.

I am working on an REST api integration where I am getting the details of a asset from a third party system. I need to compare the API response values with what is available in Salesforce and if they are different, I need to update the asset in Salesforce. The fields that I will be comparing are below.

InstallDate
PurchaseDate
Cancelled_Date__c (Custom Field)
Name
ProductCode
SalesChannels__c (Custom Field)
ProductOptions__c (Custom Field)

I am not sure of a sureshot way to compare the InstallDate, PurchaseDate and Cancelled_Date__c. When I query the Asset in Salesforce, I am getting these in GMT, but the webservice is sending these values in CST. I used the timezone class to determine the offset and use that, but it does not provide the results what I want. I work in IST and I am getting a result when I test my service in the morning and a different result when I test the service in the evening.

Can someone help on how do I go about comparing these date fields to determine whether an asset needs to be updated or not?

4
  • Does this answer your question? How to convert time to currentuser timezone?
    – Phil W
    Jun 1, 2022 at 18:51
  • Thanks for your response. I understand what was mentioned in the post. However, I am little confused about how to convert both fields into UTC before comparing. The API response is providing the date in datetime format ("renewalDate": "2022-05-31T00:00:00") where as the InstallDate on the Asset object is a date field, not a datetime. Does date field consider timezone? Before comparing, do I need to convert the InstallDate into a datetime field, convert to UTC and then compare? Jun 3, 2022 at 4:40
  • Please edit the question to include code snippets of your existing code and be explicit about what is not working for you. Some examples of the data from the database and REST response would help a lot too.
    – Phil W
    Jun 3, 2022 at 5:46
  • I was able to resolve the issue. The webservice response is coming as CST and it always has the time component as 00:00:00. So, I converted this datetime into date using .dateGmt() method and used that to compare the date fields on the asset object and it appears to be working without any issues. Jun 3, 2022 at 17:06

0

You must log in to answer this question.

Browse other questions tagged .