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

Limiting SOQL results
If List<Id> cid is a list of contact Id, I want to get a list of tasks associated with these contacts, but only 1 per contact Id.
Doing
[select t.Status, t.Type, t.WhoId from Task t where (t.WhoId in :cid and (t.type ='Call Completed - With Relevant Contact')) Limit 1]
returns a total of only 1 task record. I want it to return one for each contact. Is this possible? Thank you
You should do something like this:
for(Contact ct: [select Id,Name,{select Contact.Tasks from Task limit 1) from contact where Contact.MailingPostalCode='07666']{ Task[] tskList = ct.Tasks; ...}
All Answers
Try:
SELECT Contact.Name, (SELECT Task.Subject,Task.Id FROM Contact.Tasks limit 1) FROM Contact
Does not work.
1. It returns a list of contacts. Not a list of task. ANd it returns the entire list of contacts.
2. So, if the relevant data is in the su-query, how do I drill down to it?
You should do something like this:
for(Contact ct: [select Id,Name,{select Contact.Tasks from Task limit 1) from contact where Contact.MailingPostalCode='07666']{ Task[] tskList = ct.Tasks; ...}