Im trying to parse an ISO 8601 timestamp value consumed in a JSON data format to a DateTime field value in salesforce.
Class 1:
if ((fieldStatus == ‘normal’) || (fieldStatus == ‘overwritten’)) {
try {
value = VUtilities.formatSObjectFieldValue(flattenedFormData.get(key), ‘Account’,
field.Account_Field__c);
account.put(field.Account_Field__c, value);
} catch (Exception e) {
fieldStatus = ‘invalid’;
system.debug(LoggingLevel.ERROR,
‘#===[applyValuesToPatientRecords: ERROR! Invalid account field. ‘
+ ‘key = ‘ + key + ‘, ‘ + ‘value = ‘ + flattenedFormData.get(key)
+ ‘, field name = ‘ + field.Account_Field__c + ‘, exception = ‘ la e + ‘]===#’);
}
}
Vutilities has the below methods which the above class is calling:
public static Object formatSObjectFieldValue(Object fieldValue, String sObjectName, String fieldName) {
SObjectType objectType = Schema.getGlobalDescribe().get(sObjectName);
Integer stringMaxLength = objectType.getDescribe().fields.getMap().get(fieldName).getDescribe().getLength();
Schema.DisplayType fieldType = objectType.getDescribe().fields.getMap().get(fieldName).getDescribe().getType();
return formatFieldValue(fieldValue, fieldType, stringMaxLength); }
public static Object formatFieldValue(Object fieldValue, Schema.DisplayType fieldType, Integer stringMaxLength) {
Object returnValue = null;
if (fieldValue != null) {
if (
(fieldType == Schema.DisplayType.Combobox)
|| (fieldType == Schema.DisplayType.Address)
|| (fieldType == Schema.Displaytype.DateTime)
)
{
returnValue = stringifyObject(fieldValue);
if ((stringMaxLength != null) && (stringMaxLength > 0))
returnValue = ((String)returnValue).abbreviate(stringMaxLength);
}
/*else if (fieldType == Schema.DisplayType.DateTime) {
returnValue = DateTime.valueOf((String)fieldValue);
}
*/
else if (fieldType == Schema.DisplayType.DateTime) {
returnValue = ((DateTime)JSON.deserialize(JSON.serialize(fieldValue), DateTime.class));
}
}
}
return returnValue;
}
Im getting the below error
Error: exception = System.SObjectException: Illegal assignment from String to Datetime]=== Date sample - 2010-05-01T23:53:04.000+00:00