You need to sign in to do that
Don't have an account?
mavs
SOQL Count
HI
I have a String List which holds ContactIds
List<String> contactIds = new List<String>();
I need to check if there are any Tasks exits for each ContactId in the List. Can someone please give me a clue on how to do this?
I am trying the following but, i get the error Illegal assignment from Integer to LIST<Integer>
List<Integer> taskcount = new List<Integer>();
taskcount = [Select count() from Task where whoId IN :contactIds];
Please Advise
Thanks
List<Contact> contacts = [Select Id, (Select Id from Contact.Tasks) from Contact where id in:contactids];
Map<Id,Integer> contactMapCount = new Map<Id,Integer>();
for(Contact aContact : contacts)
{
contactMapCount.put(aContact.Id,aContact.Tasks.siz
e());
system.debug(aContact.Tasks.size());
}
All Answers
Integer taskcount = [Select count() from Task where whoId IN :contactIds];
Hi -
I am looking the Task count for each contactId in the list, The query you suggested will not give this.
Can you have an alternate suggestion?
Thanks
OK, I think I see what you want.
You want the Task count for each Contact, not the total count of tasks on all the contactIds.
This can do that.
List<Contact> contacts = [Select Id, (Select Id from Contact.Tasks) from Contact limit 100];
Map<Id,Integer> contactMapCount = new Map<Id,Integer>();
for(Contact aContact : contacts)
{
contactMapCount.put(aContact.Id,aContact.Tasks.size());
system.debug(aContact.Tasks.size());
}
List<Contact> contacts = [Select Id, (Select Id from Contact.Tasks) from Contact where id in:contactids];
Map<Id,Integer> contactMapCount = new Map<Id,Integer>();
for(Contact aContact : contacts)
{
contactMapCount.put(aContact.Id,aContact.Tasks.siz
e());
system.debug(aContact.Tasks.size());
}
That works.
Thank you so much.
Hi ,
I wanna do the same thing, but with opportunity . I wanna get count()/opportunity of tasks where task name != XYZ . Can you please help me modify your code to accomadate this extra where clause?