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

Retrieve Contact Id Where Event and Task Subqueries Not Null
I need to create a list of distinct Contact Ids from Contacts that have an Event or Task tied to them within a time period. I know one way to create a distinct list is to grab the WhoIds from Event and Task and add them to a Set<Id> like:
Set<Id> contactSet = new Set<Id>(); for (Event e : [SELECT WhoId FROM Event WHERE ActivityDate >=: startDate AND ActivityDate <=: endDate]) { contactSet.add(e.WhoId); } for (Task t : [SELECT WhoId FROM Task WHERE ActivityDate >=: startDate AND ActivityDate <=: endDate]) { contactSet.add(t.WhoId); }
The problem with this is that either loop could retrieve 'Too many query rows'. I could group by WhoId in either one, making an AggregateResult, but with a large enough set of Contacts, I'd run across the queryMore() limitation with AggregateResult.
So, I figured I'd try to run a query on Contact with Event and Task subqueries like:
SELECT Id, (SELECT Id FROM Tasks WHERE ActivityDate >=: startDate AND ActivityDate <=: endDate), (SELECT Id FROM Events WHERE ActivityDate >=: startDate AND ActivityDate <=: endDate) FROM Contact
How would I populate my Set<Id> contactSet with the Contact Ids where the Task or Event subquery does not equal null?
Thanks, I appreciate the help.
A
I figured it out. For anyone interested: