You need to sign in to do that
Don't have an account?
CommaSpace
Updating Event time from GMT/UTC to Local Time & account for daylight savings
Hello! I'm trying to use an apex trigger to update the starttime of an event. I have a visualflow intake form that creates an event on a future date based on the information provided. The event is created in GMT and after scouring the interwebs and piecing code/ideas together I think I am making progress, but now I'm getting an error Line 20: Variable does not exist: time.
Would greatly appreciate if you'd take a look and provide input/assistance.
Best,
Ruth
Would greatly appreciate if you'd take a look and provide input/assistance.
Best,
Ruth
trigger FindTime on Event (before insert) { //If type is "call" Pull event startdatetime //Pull month from startdatetime //Event Months during daylight savings add 6hrs //Event Month after daylight savings add 5 hrs //Event Months before daylight savings add 5 hrs //Event Month of March, check which week event date falls in and add 6 hrs if in or after the 3rd week of the month; otherwise add 5hrs. //Event Month of November, check which week event date falls in and add 5 hrs if in or after the 2rd week of the month; otherwise add 6hrs. //Setting up trigger info Public Date mydate{get;set;} Public Time mytime{get;set;} for (Event id: trigger.new){ if(id.type =='Call'){ DateTime dT = id.startdatetime; myDate = date.newinstance(dT.year(), dT.month(), dT.day()); mytime = time.newinstance(dT.hour(), dT.minute(), dT.second()); Integer WeekOfMonth = Math.ceil((Double)(id.startdatetime().Day()) / 7).intValue(); //if Month is greater than 3 and less than 11 If(dt.month() >3){ IF(dt.month()<11){ dt.addHours(6); } //following code is if month = 12 (because the 2nd if above returned false) dt.addHours(5); // following code is when the first IF returns false dt.addhours(5); } //closing bracket on first set of if's //starting IF set for dates in March else If (dt.month = 3){ If(weekofmonth >= 3){ //if week of month is greater than or equal to 3 (meaning into the 3rd week, meaning after the 2nd weekend) then DST is in effect; add 6 hrs dt.addHours(6); dt.addHours(5); }} //starting Else set for dates in November Else //last option is for event to be in november If (weekofmonth >= 2){ //meaning it's in the 2nd week or after the first weekend dt.addHours(5); dt.addHours(6); }}}}
Saurabh Sagar Gulati
You are getting error on Line 20 because Time.NewInstance has 4 parameters but you have used only 3. If you dont want to use the 4th parameter mention it as 0.
CommaSpace
Hi Saurabh, Thank you! That helped and then I figured out a few more things and have the updated code as shown below. Now, interestingly, the trigger passes the test class but it doesn't actually update the event record. Any suggestions?