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
MrunaliniMrunalini 

how can we display tasks of contact object in vf page using custom controller and also view and edit the task by adding view and edit link with each row of task.

NagendraNagendra (Salesforce Developers) 
Hi Mrunalini,

May I suggest you please refer to the sample code below and tweak it as per your requirement which whould help.

Apex Controller:

public class contactActivityHistory {
    public Task[] getListTasks() {
        List<Contact> cntct = [SELECT Id, Name FROM Contact];
        List<Id> contactIds = new List<Id>();
        for(Contact cn : cntct) {
            contactIds.add(cn.Id);
        }
        
        List<Task> tskList = [select whoid,subject,status,LastModifiedDate from task where whoid in : contactIds order by LastModifiedDate desc];    
        return tskList;
    }
    
    
}
Visual Force Page:
<apex:page controller="contactActivityHistory">
  <apex:pageBlock title="Activity History">
      <apex:pageBlockSection >
          <apex:pageBlockTable value="{!ListTasks}" var="tsk">
              <apex:column headerValue="Contact" value="{!tsk.WhoId}"/>
              <apex:column headerValue="Subject" value="{!tsk.Subject}"/>
              <apex:column headerValue="Status" value="{!tsk.Status}"/>
              <apex:column headerValue="Modified Date" value="{!tsk.LastModifiedDate}"/>
          </apex:pageBlockTable>
      </apex:pageBlockSection>  
  </apex:pageBlock>
</apex:page>
How to view and edit the task by adding view and edit link with each row of task: Hope this helps.

Kindly mark this as solved if my reply was helpful so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue.

Thanks,
Nagendra