+ Start a Discussion
Cris9931Cris9931 

why my DateTime field keeps converting in local time zone?

I have a DateTime text field.

User-added image

I created a short trigger to convert this DateTime text in actual DateTime.
 
List<Id> listWoId = new List<Id>();
        
        for(SVMXC__Service_Order__c loopwo : Trigger.new){
              listWoId.add(loopwo.Id);
        }
        
        List<SVMXC__Service_Order_Line__c> currentWL = [SELECT ID, Name, SIG_Start_Date_Time_Device__c , SIG_End_Date_Time_Device__c from SVMXC__Service_Order_Line__c where SVMXC__Service_Order__c =: listWoId]; 
        
        for(SVMXC__Service_Order_Line__c workDetail : currentWL ){
        
          
          DateTime dt = DateTime.valueOf(workDetail.SIG_Start_Date_Time_Device__c);
          System.debug('Work Detail Number: ' +workDetail.Name + '   #####     ' + 'DateTime :' + dt);

        }


If I take a look on my work details I see that Start Date/Time - Device is not the same with what I received in my system debug...
 
This is how it looks without any time conversion, its basically a text of DateTime.

User-added imageBut when I system debug this I get converted value:

User-added imageHow can I get the original value from the WEB and avoid the time conversion? Please help.. I'm stuck with this.
Best Answer chosen by Cris9931
Cris9931Cris9931

This is the answer that works:

 

DateTime dt = DateTime.valueOfGMT(workDetail.SIG_Start_Date_Time_Device__c);

All Answers

AnudeepAnudeep (Salesforce Developers) 
You should be doing a System.debug(workDetail.SIG_Start_Date_Time_Device__c) if you want the original value

As per Datetime class documentation

valueOf(fieldValue)

Converts the specified object to a Datetime. Use this method to convert a history tracking field value or an object that represents a Datetime value.

Also, I recommend trying the solution listed here

Let me know if this helps, if it does, please close the query by marking it as solved. It may help others in the community. Thank You!

 
Cris9931Cris9931

This is the answer that works:

 

DateTime dt = DateTime.valueOfGMT(workDetail.SIG_Start_Date_Time_Device__c);
This was selected as the best answer