You need to sign in to do that
Don't have an account?
srikanth11
max date populate
i am inserting 4 tasks at a time and when they are inserted i want the max date in four of them to populate in the placement object plz help me how to do this
function readOnly(count){ }
You need to sign in to do that
Don't have an account?
i am inserting 4 tasks at a time and when they are inserted i want the max date in four of them to populate in the placement object plz help me how to do this
date d=[slect max(activitydate) from task where id=:whatid];
this is the query i wrote but it says there is no max operator so plz help how to get the max date from a set of records what function i have to use
Hi,
You will have to use AggregateResult for this. Use Max function on Date.
Hope this helps.
Thanks,
Devendra
hi can u give an example for my code so that i will know how to use it
Hi,
Try This,
Hope this helps.
Thanks,
Devendra
If you're trying to find the MAX date out of the records you're inserting - you're not going to be able to SOQL query for them while you're inserting them....
My suggestion would be to add some additional code to interrogate the data you're entering to find the max date that way - then use THAT to update the other object.
-Andy
Hi techman97,
One more way to find Max date is to query something like this:
A max date would be retrieved by reversing the order and keeping limit as 1.
For e.g. Order objOrder=[Select Id, Date__c from Order__c (condition if any) ORDER BY DESC limit 1];
Date d=objOrder.Date__c;
System.debug('Max Date :'+d);
What is you view on this?
Thanks,
Devendra
The kicker is that the OP said he was trying to find the MAX of records that he's inserting. If he's doing this within a Trigger - those records haven't been committed to the database yet, and thus cannot be retrieved via a SOQL query until after the transaction / APEX session has finished.
While the OP is creating these new records for insert, it makes sense to just slide in the logic at that point.
Something to the tune of...
(top of method)
Date dteMaxDate;
(in method loops or other logic)
if(datevaluetobetested > dteMaxDate) { dteMaxDate = datevaluetobetested; }
-Andy