function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
steve456steve456 

Help with a Trigger

I am currently using two objects in the picture 

 

Account & Case

 

 

Account has a field Time_Zone__c which is a picklist with values EST , PST , CST ,MST

 

Case also has the same field Time_Zone__c

 

I have written trigger on case  which pulls the TimeZone automatically based on the Account Field.

 

Till here no issues

 

I have one more Field Client _Date__c(Date/Time) on Case which takes the same value as Created Date 

 

I have done this by just giving

 

Client_Date__c=System.Now()

 

 

My main issue is 

 

The Client_Date__c is taking the time zone of the created by user .But I want this to get updated based  on Time Zone field  on Case which is pulled from  Account 

 

 

paulo.orquillopaulo.orquillo

so you want the client_date__c to reflect the timezone selected on timezone field on accounts.

 

use the format method.

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_datetime.htm

 

Modified this a bit by adding the Timezone.

 

Datetime GMTDate =
Datetime.newInstanceGmt(2011,6,1,12,1,5);
String strConvertedDate =
GMTDate.format('MM/dd/yyyy HH:mm:ss',
'EST');
// Date is converted to
// the new time zone and is adjusted
// for daylight saving time.
System.assertEquals(
'06/01/2011 07:01:05', strConvertedDate);