You need to sign in to do that
Don't have an account?

Date to string one day less
Hi,
I converted my date field in string, so I can updated my other field in account.
for (Account acc: [SELECT Id, Data_pedido_AR__c, Data_pedido_SA__c FROM Account WHERE id IN: ids]){
for (Case c: trigger.new) {
if(c.motivo__c == 'Formandos AR' && c.Data_pedido_AR__c != null && Trigger.oldMap.get(c.id).Data_pedido_AR__c != c.Data_pedido_AR__c){
Datetime d = Date.Valueof(c.Data_pedido_AR__c);
String dateStr = d.format('dd/MM/yyyy');
System.debug('::::::::::: ' + dateStr) ;
acc.Data_pedido_AR__c = dateStr;
}
update acc;
It works fine but in my account my field is one day less.
If I put c.Data_pedido_AR__c = 20/05/2014
I get acc.Data_pedido_AR__c = 19/05/2014
Why?
I converted my date field in string, so I can updated my other field in account.
for (Account acc: [SELECT Id, Data_pedido_AR__c, Data_pedido_SA__c FROM Account WHERE id IN: ids]){
for (Case c: trigger.new) {
if(c.motivo__c == 'Formandos AR' && c.Data_pedido_AR__c != null && Trigger.oldMap.get(c.id).Data_pedido_AR__c != c.Data_pedido_AR__c){
Datetime d = Date.Valueof(c.Data_pedido_AR__c);
String dateStr = d.format('dd/MM/yyyy');
System.debug('::::::::::: ' + dateStr) ;
acc.Data_pedido_AR__c = dateStr;
}
update acc;
It works fine but in my account my field is one day less.
If I put c.Data_pedido_AR__c = 20/05/2014
I get acc.Data_pedido_AR__c = 19/05/2014
Why?
To avoid this use formatGmt(String) instead of format()
Forcetree.com - Code Samples and Tips (http://www.forcetree.com/" target="_blank)
All Answers
acc.Data_pedido_AR__c = c.Data_pedido_AR__c;
?
If not, what type is CASE.Data_pedido_AR__c? It looks like ACCOUNT.Data_pedido_AR__c is supposed to be a string. Can you change the type fo Account.Data_pedido_AR__C to match the type on the case?
To avoid this use formatGmt(String) instead of format()
Forcetree.com - Code Samples and Tips (http://www.forcetree.com/" target="_blank)