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

List of Leads with call, task in SOQL
Hi,
I need to show a list of those leads on which any task or call is created. I have wrote the following query but it is not working.
Select Id, Name from Lead where Id IN (SELECT Who.Id FROM Task where Who.Type='Lead') limit 10
Can anyone help me?
Thanks,
Rohitash
I need to show a list of those leads on which any task or call is created. I have wrote the following query but it is not working.
Select Id, Name from Lead where Id IN (SELECT Who.Id FROM Task where Who.Type='Lead') limit 10
Can anyone help me?
Thanks,
Rohitash
Try using below code.
List<Task> taskList = new List<Task>();
List<id> leadsId = new List<id>();
List<Lead> leadList = new List<Lead>();
taskList = [select id,WhoId from Task];
for(Task str : taskList ){
leadsId.add(str.WhoId);
}
leadList = [select name from lead where id IN :leadsId];
system.debug(leadList);
P.S. If it helps you then mark this answer as 'Best Answer'
All Answers
Map<id,Task> taskMap=new Map<id,Task>([SELECT Who.Id FROM Task where Who.Type='Lead']);
List<Lead> newlead =[Select Id, Name from Lead where Id IN: taskMap.keyset() limit 10 ];
system.debug('newlead==============>'+newlead);
Try using below code.
List<Task> taskList = new List<Task>();
List<id> leadsId = new List<id>();
List<Lead> leadList = new List<Lead>();
taskList = [select id,WhoId from Task];
for(Task str : taskList ){
leadsId.add(str.WhoId);
}
leadList = [select name from lead where id IN :leadsId];
system.debug(leadList);
P.S. If it helps you then mark this answer as 'Best Answer'
Thanks for your reply. I have created a visualforce page with javascript remoting, in this I will show the list of leads with no task created. Now I want to add a button for each lead. When click on it, it will open lead's create email form, lead's create call form in the fancy box and after submitting these form call will be created.
Can you help me again to achieve this task.
Thanks,
Rohitash