+ Start a Discussion
KlivingstonKlivingston 

Activity History Visualforce page

Hi All

I would like to create a visualforce page replacing the standard related list. This is because of the long list of records we have and we would like to see only he records from last 3 months.

Can you please help me to write the code for it.

Here is what I have now:

public class ActiveHistoryClass
{
  
    public String LastModifiedDate { get; set; }
    public String ActivityDate { get; set; }
    public String IsTask { get; set; }
    public String Subject { get; set; }
    public String Name { get; set; }
    public String id { get; set; }
    public String OutbaseActivityHistory { get; set; }

    private ApexPages.StandardSetController controller;
   
    public List<Account> getActiveHistory(){
        return [SELECT (SELECT Subject,IsTask, ActivityDate,
                 LastModifiedDate  FROM ActivityHistories)
                FROM Account];
}}





<apex:page controller="ActiveHistoryClass" tabStyle="Report" >

    <apex:pageBlock >
      <apex:pageBlockTable value="{!OutbaseActivityHistory}" var="c">
            <apex:column title="Activity History">
               <apex:outputLink value="/{!Id }" target="_blank">{!Name}</apex:outputLink>
            </apex:column>     
             '<apex:column value="{!c}" onclick="window.open('https://cs17.salesforce.com/{!id}','_blank')"/>'
           
            <apex:column value="{!Subject}"/>
            <apex:column value="{!IsTask}"/>
            <apex:column value="{!ActivityDate}"/> 
            <apex:column value="{!LastModifiedDate    }"/>    
                 
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>


At the moment it does not show anything! I think I need to map Account with the activity but I am not sure how!

Thank you.

PeaceMakerPeaceMaker
Replace

<apex:pageBlockTable value="{!OutbaseActivityHistory}" var="c">

with

<apex:pageBlockTable value="{!ActiveHistory}" var="c">

will work.

Mark this is as solution if it solves your problem.
KlivingstonKlivingston
That did solve the issue but now I get this error:

Collection size 1,077 exceeds maximum size of 1,000.

I know there are some guide to come over this issue, but that is not required yet,  because if I map Accounts to their activity history the list would be much less than 1000 records.

So I need to map Accounts to their individual Activity History. Can you please help to complete the code.

Thank you.
PeaceMakerPeaceMaker
Try modifying the code... i modified little... rest all yours...



Public Class MapTestingController {
    public Map<Account,List<ActivityHistories>> mapObj{get;set;}
    public MapTestingController() {
        mapObj = new Map<Account,List<ActivityHistories>>();

List<ActivityHistories> listact = new List<ActivityHistories>([Write a select query to pull all the Activity History with Accounts using whatId i guess]):

for(ActivityHistories a: listact){
if(!mapObj.containskey(a.accountId))
          mapObj.put(a.AccountID,List<ActivityHistories>);  // a.AccountID = Account field in ActivityHistories
       else
           mapObj.get(a.accountId).add(a);
       }
}
}     


<apex:page controller="MapTestingController">
   <apex:form >
       <apex:pageBlock >
<!-- use the map name as a value and takes a variable as a key -->
           <apex:pageBlockTable value="{!mapObj}" var="key">
               <apex:column headerValue="Key Values">
                    {!key} <!-- display the key Values of map -->
               </apex:column>
               <apex:column headerValue="Values">
                    {!mapObj[key]} <!-- display the values of corresponding keys-->
               </apex:column>
          </apex:pageBlockTable>
      </apex:pageBlock>
   </apex:form>
</apex:page>