You need to sign in to do that
Don't have an account?
Custom Time Field question.
Hello,
I have a custom Time field called Scheduled_ET__c. The drop-down displays time in 15 minute increments, however we do not want the user to select 15 or 45 minute increments. Since there is no way I can find to eliminate 15 or 45 from the drop-down I need to find another soultion.
My thoughts are...use a validation rule or Apex to change the minutes to a 30 min increment.
Is it possble to extract the minutes part of a custom time field in Apex and how would one do that?
My rounding logic would be if user enters <16 round down to 00, >16 and <45 round to 30, >45 up to 00 and increment hour.
Any thoughts or suggestions would greatly be appreciated.
Kind regards,
Robert
Hi Robert,
Using validation rule you can only prevent the record from getting inserted but rounding off wont work, for that you need to write an apex trigger.
Also i am assuming the field is of date/time type.
Hi Ankit,
I started working on an APEX trigger to perform the rounding, however I am having trouble dealing custom Time field called Scheduled_ET__c. Specifically, how to extract minutes from the time field for rounding logic.
Time schTime = cs.Scheduled_Time_ET__c;
Time.newInstance(
schTime.hour(),
schTime.minute(),
schTime.second(),
schTime.millisecond());
System.Debug('schTime.minute() = ' + schTime.minute());
If(schTime.minute() < 16)
{ schtime.minute()=00; }
I have made some changes...
System.Debug('Scheduled_Time_ET__c = ' + Case.Scheduled_Time_ET__c);
Time schTime = cs.Scheduled_Time_ET__c;
Time.newInstance(
schTime.hour(),
schTime.minute(),
schTime.second(),
schTime.millisecond());
System.Debug('schTime.minute() = ' + schTime.minute());
Integer MyMin = schTime.minute();
If(MyMin < 16)
{
System.assertEquals(MyMin, 00);
}
System.Debug('schTime.minute() = ' + schTime.minute());
I am getting this error on the bold line: System.AssertException: Assertion Failed: Expected: 15, Actual: 0