function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
rohitash yadavrohitash yadav 

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
Best Answer chosen by rohitash yadav
SFDC Coder 1SFDC Coder 1
Hi 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

surya kanadhipatlasurya kanadhipatla
please try as below:(it worked for me)

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);
SFDC Coder 1SFDC Coder 1
Hi 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'
This was selected as the best answer
rohitash yadavrohitash yadav
Hi Surya & SFDC Coder 1,

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
surya kanadhipatlasurya kanadhipatla
Rohitash, Please see the below sample . Here sample creates a Case instead of Call/Email. Please see if you can update it for your needs. Once done its very easy to use VF page as detailed button once clicked it opens the form in form of Pop up and allows user to input required values and finally submit (Save) creates email/Case. https://developer.salesforce.com/page/Creating_Custom_Web-To-Case_Forms_Using_Visualforce_and_Sites