I have a list of accounts that I need to get the last meeting that has been held with each account. Unfortunately the following SOQL doesn't work. I get the following error: "field ActivityDate does not support operator MAX

SELECT WhatId, MAX(ActivityDate) 
FROM Task 
WHERE Type = 'Meeting' AND WhatId in :accountIds

I don't really want to select all activities and loop through them to find the max for each account. Any other solutions?


I think this would do the trick

SELECT id, (select activitydate from tasks
            where type = 'Meeting'
            order by activitydate desc limit 1)
FROM Account
WHERE ID in :accountIds
  • Thanks! Why didn't I think of that? – Daniel Hoechst Aug 23 '13 at 17:14
  • It's been a long week - sometimes you need a second pair of eyes. Glad it helped. – Doug B Aug 23 '13 at 19:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.