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

Calculations with Time
I can't figure out how to handle this issues. We have a problem where we have to calculate and compare time. Basically an order has to be placed in submitted status before 12:00 pm if the shipping address is eastern time. We have to report on our SLAs for orders by timezone.
So an order is recieved 8:00 am pacific time and must be submitted by changing the status to Submitted before 12:00 pm. We are trying to report how many orders are put in the submitted status after 12:00pm to report how many orders went out of the SLA. I hope this describes it. Right now we are using a series of formula and check box fields. I was thinking there might be a different way. Any suggestions are welcomed.
Thanks,
Rachael
trigger on Order__c (before insert, before update)
{
for (Order__c ord : trigger.new)
if (ord.Status__c == 'Submitted' && Datetime.now().hour() > 12) //if status submitted and the hour is past 12
ord.SLAElapsed__c = true; //set the checkbox
}
All Answers
You could have a checkbox on Order.
A before update trigger, which checks if the time is past 12, and if so, sets this checkbox.
If youre web of workflows and formulae is getting too much to handle, a simple trigger could prove effective.
I want to solve it with a trigger. I guess my main issue is being able to isolate the time from date/time fields. I have researched to find ways to calculate time but I can't find anything. I only see calculations based on date. If anybody knows where to find sample code for calculating time or comparing time or working with time, I would appreciate the assistance.
trigger on Order__c (before insert, before update)
{
for (Order__c ord : trigger.new)
if (ord.Status__c == 'Submitted' && Datetime.now().hour() > 12) //if status submitted and the hour is past 12
ord.SLAElapsed__c = true; //set the checkbox
}
This is great. I can take it and apply it to other parameters. What is your suggestion for the test code?