質問

the below line is giving me 'FIELD_INTEGRITY_EXCEPTION' in salesforce . please provide me the alternative for this .

imr.Assigned_DTM__c = DateTime.valueOfGmt(('06/08/2013 06:30:22').replaceAll('/','-'));

役に立ちましたか?

解決

The issues is that you use incorrect format

System.debug(DateTime.valueOfGmt(('06/08/2013 06:30:22').replaceAll('/','-')));

System.debug(DateTime.valueOfGmt(('2013/08/06 06:30:22').replaceAll('/','-')));

console output:

08:19:40:061 USER_DEBUG [3]|DEBUG|0012-02-03 06:30:22
08:19:40:061 USER_DEBUG [5]|DEBUG|2013-08-06 06:30:22

as you can see from the debug, the first variant returns incorrect datetime value.

Official documentation says the following

valueOfGmt Returns a Datetime that contains the value of the specified String. The String should use the standard date format “yyyy-MM-dd HH:mm:ss” in the GMT time zone

correct your initial string with datetime.

UPDATE

String myDate = '06/08/2013 06:30:22';
String stringDate = myDate.substring(6,10) + '-' + 
                    myDate.substring(3,5) + '-' +
                    myDate.substring(0,2) + ' ' +
                    myDate.substring(11,19);
DateTime dt = datetime.valueOf(stringDate);
System.debug(String.valueOfGmt(dt));

log: dt|"2013-08-06T03:30:22.000Z"

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top