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
Shravan Kumar 71Shravan Kumar 71 

Showing all the related activity :

I would like to show all the open tasks across the Org based upon the Email ID. The below VF & Class is giving me the results of all the task irrespetive of Email ID. Can someone help me to fix the code here :

Class :

public class ActivitySearchController {

    Public List<Task> TaskList{get;set;}
    String currentEmail ; 
    public ActivitySearchController(ApexPages.StandardController controller) {
        currentEmail  = ApexPages.CurrentPage().getparameters().get('Email');
     TaskList = [Select subject,id, who.Email, Type, Who.Type, whoID, priority, status, ActivityDate
                FROM Task WHERE who.Email=:currentEmail AND Status = 'Open'];
    if(TaskList.size() == 0)
    Apexpages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,''+'No Tasks to Display'));


<apex:page standardController="Lead" extensions="ActivitySearchController"  >
    <apex:form >
        <apex:pageBlock id="pb">
            <apex:pageMessages ></apex:pageMessages>
            <apex:pageBlockTable value="{!TaskList}" var="d">
                 <apex:column headerValue="Record ID">   
                    <apex:outputField value="{!}">                      
                    </apex:outputField> </apex:column>
                <apex:column headerValue="Subject">   
                    <apex:outputField value="{!d.subject}">  
                        </apex:outputField> </apex:column>
                <apex:column headerValue="Type">   
                    <apex:outputField value="{!d.Type}">                         
                    </apex:outputField> </apex:column>
                <apex:column headerValue="Status">   
                    <apex:outputField value="{!d.Status}">                      
                    </apex:outputField> </apex:column>
Best Answer chosen by Shravan Kumar 71
Khan AnasKhan Anas (Salesforce Developers) 
Hi Shravan,

I trust you are doing very well.

The WhoId and WhatId fields on Task are Polymorphic (, means they can point to multiple target objects. You can't query relationships through them like you can for normally-related objects. Ask Salesforce Support to enable "Polymorphic SOQL" in your organization, then you'll be able to determine whether it's Lead or Contact. 

Please refer to the below link with a similar discussion which might help you further with the above issue.

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in future.

Thanks and Regards,
Khan Anas