You need to sign in to do that
Don't have an account?
grandak koy
Subtracting date/time from date.today()
If I did:
Date fiveDays =date.today().Add days(-5)
Order_received_date__c ==five days
Would that bring back a date result or a date/time results since order_received_date__c is a date/time field?
If i wanted to convert the order received date to bring back a date results should i:
Date order = order_received_date__c.date();
Then do this:
Order==five days
To see if my order_received_date__c was five days ago?
I have a trigger to send an email if an order was five days ago but its not shooting out when the order received date was five days ago from today. Does the date time have to be converted to date to work?
Date fiveDays =date.today().Add days(-5)
Order_received_date__c ==five days
Would that bring back a date result or a date/time results since order_received_date__c is a date/time field?
If i wanted to convert the order received date to bring back a date results should i:
Date order = order_received_date__c.date();
Then do this:
Order==five days
To see if my order_received_date__c was five days ago?
I have a trigger to send an email if an order was five days ago but its not shooting out when the order received date was five days ago from today. Does the date time have to be converted to date to work?
<pre>
Date fiveDaysAgo = Date.today().addDays( -5 );
Date orderReceivedDate = myOrder.Order_Received_Date__c.date();
if ( orderReceivedDate == fiveDaysAgo )
{
// send an email...
}
</pre>
If you're willing to spend a query, you could also do something like this:
<pre>
List<Order> fiveDayOldOrders =
( [ SELECT Id
FROM Order
WHERE ( Id IN :myOrderIds
AND Order_Received_Date__c = LAST_N_DAYS:5 // in the last 5 days
AND Order_Received_Date__c < LAST_N_DAYS:4 // older than the last 4 days
)
]
);
</pre>
I was able to do it in my trigger but when I went to test it, it does not over. if i keep it as a date/time it covers.
My code is to trigger when the order_received date is five days ago.
In my test class I have it set:
It covers everything but this line:
orders.add(new Reserve__c(Account__c =order.Account__c,Status__c = ’Received’));
When I change this line in my class:
if( orderDate==fiveDays ){
to
If(reserve.Order_received__c ==fiveDays){
Then it covers that line:
orders.add(new Reserve__c(Account__c =order.Account__c,Status__c = ’Received’));
So I was wondering how in my test class, I can convert Order_received__c to a date field. In the test class its still a date/time field
1) Since "if(reserve.Order_received__c ==fiveDays){" works, you could change the class and leave it that way.
2) change the test code from
res.Order_received__c = System.Today().addDays(-5);
to
res.Order_received__c = System.now().addDays(-5);
I can't think of anything else to try right now, but if I do, I'll post it here.