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
TinkuTinku 

Visual force page to display the Activity History

Hello all,

 

I am new to salesforce. And this is my first try at VisualForce Page in an organization.

 

The requirement is to display the activity history in a seperate page. Right now, since activity history is a related list in Accounts/Contacts, the information gets displayed in the same page as in Accounts/contacts.

 

I am planning to write a VF page and give a button on the related list, which will take the users to a new page of activity history.

 

Here is the VF page and the related class. I am getting a List has no rows for assignment to SObject errors.The error comes when i click the button.

Can anyone please help me out.

 

<apex:page standardController="Task" extensions="MarketingGeniusTasksController">
<apex:form >
<h1>Activity History: Marketing Genius Emails</h1>

<apex:pageblock >
<apex:pageBlockTable value="{!Task}" var="Task" >

<apex:column headerValue="Status"/>
<apex:outputfield value="{!task.Status}"/>

<apex:column headerValue="Subject"/>
<apex:outputfield value="{!task.Subject}"/>

<apex:column headerValue="Priority"/>
<apex:outputfield value="{!task.Priority}"/>

<apex:column headerValue="TLC Activity Type"/>
<apex:outputfield value="{!task.Vmail__c}"/>

</apex:pageBlockTable>
</apex:pageBlock>


</apex:form>
</apex:page>

 

 

public class MarketingGeniusTasksController 
{
 
    Task tk;
    Task tsk;
 
 public MarketingGeniusTasksController(ApexPages.StandardController stdController)
 {
 this.tk = (Task)stdController.getRecord();
 tsk = [Select Status, Subject, Priority, Vmail__c from Task where Id=:tk.Id]; -->error at this line.
 }
 
 public string getStatus(){
 return tsk.Status;
 }
 
 public string getSubject(){
 return tsk.Subject;
 }
 
 public string getPriority(){
 return tsk.Priority;
 }
 
 public string getTLCActivityType(){
 return tsk.Vmail__c;
 }
 }
gm_sfdc_powerdegm_sfdc_powerde

You shouldn't be using the standard controller for task since you don't intend to display one task.  You might want to write your controller as a custom controller (with controller attribute defined in apex:page tag) for this.  You would also pass the parent record id (account or contact) as a parameter to this vf page, which you can read in a "init" method and query tasks by parent id field.  Hope this helps!

TinkuTinku

Thank you for the reply.

 

Will try out your solution and if i run into any issues, will post it.

 

Thanks once again!

TinkuTinku

 

I made some modifications in my code. Now it is displaying all the activities created in the organiztion. I want to filter it out based on the particular Account or Contact. Any suggestions on how i can accomplish that with the code i already have.

 

 

public class MarketingGeniusTasksController 
{
       List<Task> tk; 
 
 public MarketingGeniusTasksController(ApexPages.StandardController Controller)
   {
 }
 
  Public List<Task> getResults()
  {     
        return tk;
  }
 
 public PageReference gettk()
 {
   String userId=UserInfo.getUserId();
   UserId=userId.Substring(0,15);
   System.debug('UserId=='+UserId);
   tk=[Select Status, Subject, Priority, OwnerId, Owner.Name, WhatId, What.Name, WhoId, Who.Name, Vmail__c, RecordTypeId, LastModifiedDate from Task where Subject='Enterprise Marketing Genius Email'];
   return Null; 
 }
}

 

<apex:page standardController="Task" extensions="MarketingGeniusTasksController" action="{!gettk}">

<apex:form >
<h1>Activity History: Marketing Genius Emails</h1>

<apex:pageblock >

<apex:pageBlockTable value="{!results}" var="tsk">

<apex:column >
<apex:outputlink value="/{!tsk.Id}">{!tsk.Subject}</apex:outputLink>
<apex:facet name="header"> Subject </apex:facet>
</apex:column>

<apex:column >
<apex:outputLink value="/{!tsk.WhoId}">{!tsk.Who.Name}</apex:outputLink>
<apex:facet name="header"> Name</apex:facet>
</apex:column>

<apex:column >
<apex:outputLink value="/{!tsk.OwnerId}">{!tsk.Owner.Name}</apex:outputLink>
<apex:facet name="header"> Assigned To </apex:facet>
</apex:column>

<apex:column value="{!tsk.LastModifiedDate}"/>
<apex:column value="{!tsk.Vmail__c}"/>
<apex:column value="{!tsk.Status}"/>

</apex:pageBlockTable>

</apex:pageBlock>

</apex:form>
</apex:page>

 

Thank you!!

 

TinkuTinku

Since i am new to Salesforce, can you please suggest me on how to pass the parent record id as a parameter to the vf page?

 

Thanks in advance!