Note i can provide full code examples for running , but for brevity i am including snippets at this time

i have a query that i am dynamically retrieving all fields and placing them in an object to later serialize

        set<Id> recordIds = objIDMap.get(objectName);
        String objQuery = 'SELECT '+ String.join( fields, ',' ) + ' FROM ' + res.getName() +    ' WHERE ' + ' id IN:recordIds';
        system.debug('objQuery: '+objQuery);
        recordsMap.put(objectName, new map<Id, SObject>(Database.query(objQuery)));
       SObject record = recordsMap.get(objectName).get(recordId);
       List<SObject> records = new list<Sobject>{record};

when the records variable is being assigned, the createddate equals this in the log

 {...,"CreatedDate":"2020-11-11T19:54:54.000Z","CreatedById":"00536000002oIZ5AAM", ...}

but when the system debug records is viewed the createddate equals this, it looks like the time zones have been stripped

 CreatedDate=2020-11-11 19:54:54, CreatedById=00536000002oIZ5AAM,

and later in the program when i write the field to the json object the time zone stays off the value

is this due to being in a generic sObject? i want to retain all fields as the values queried from the system

1 Answer 1


Debug logs always show date/time values in UTC. Similarly serializing Date/time values to JSON results in UTC values. As such there's little need to retain the Zulu "timezone" identifier.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .