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

Retrieving Values from SOQL Subqueries
I'm trying to slim down the number of SOQL queries I run in a trigger.
I currently have these two loops for retrieving Tasks and Events for a Contact:
for (Event e : [SELECT Id FROM Event WHERE WhoId =: fromId]) { Event fe = new Event(Id = e.Id, WhoId = toId); updateEvent.add(fe); } for (Task t : [SELECT Id FROM Task WHERE WhoId =: fromId]) { Task te = new Task(Id = t.Id, WhoId = toId); updateTask.add(te); }
They work just fine. However, as mentioned, I would like to reduce my SOQL #. I'd like to be able to run these queries using something like this:
for (Contact c : [SELECT (SELECT Id FROM Events), (SELECT Id FROM Tasks) FROM Contact WHERE Id =: fromId]) { Event fe = new Event(Id = c.Events.Id, WhoId = toId); updateEvent.add(fe); Task te = new Task(Id = c.Tasks.Id, WhoId = toId); updateTask.add(te); }
Is this possible, and if so, how do I reference the Id fields for both Events and Tasks? I think I've done this somewhere else, I just can't find the example.
Thanks in advance,
Adriel
Thanks Eric,
I found that it was much easier for me to create a VF page and custom controller. The VF page allows me to use up to 100 SOQL queries.
Thanks again!
All Answers
Try:
Thanks Eric,
I found that it was much easier for me to create a VF page and custom controller. The VF page allows me to use up to 100 SOQL queries.
Thanks again!