I have a visualforce page that is supposed to display the activity history for the Contact record for ONLY the current user. However, it seems to be leaving out some of the activity history, with no apparent consistency to the records it leaves out.
On this Contact for example, it displays a dozen activity history records, but leaves out four seemingly at random.
Here are six that are showing. This is an incomplete list:
Here is the complete list of the four not showing:
As you can see, there does not seem to be a consistent pattern. For example, a record created on 3/18/2016 is showing. But, a record created afterwards, on 3/21 is NOT showing. And then a record created later at 5/14 is showing again.
Here is what this looks like on the vf page. If I search for "Left VM again", there are 0 results. (There are other activities from the same day 3/21, that are showing up, this is why I searched by the comment field).
Here's the code for the vf page, and the apex controller that runs the query.
VF:
<apex:page standardController="Contact" extensions="ActivityHistoryOnContact" showHeader="true" sidebar="false" >
<style>
.activeTab {background-color: #081f3f; color:white; background-image:none}
.inactiveTab { background-color: lightgrey; color:black; background-image:none}
</style>
<apex:form >
<apex:pageblock >
<apex:pageBlockSection >
<apex:pageBlockSectionItem >
<apex:commandLink value="Log A Call" action="{!URLFOR($Action.Contact.Log_a_Call,Contact.id)}" target="_blank" styleClass="btn" style="text-decoration:none;padding:4px;"></apex:commandlink>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageblock>
<apex:repeat value="{!ListTasks}" var="tsk" id="repeat">
<apex:pageblock >
<apex:pageBlockSection >
<apex:pageBlockSectionItem >
<apex:outputLabel value="Subject" for="tsk.Subject" style="font-weight:bold"/>
<apex:outputLink value="/{!tsk.id}" target="_blank">{!tsk.Subject}</apex:outputLink>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Comments" for="!tsk.Description" style="font-weight:bold"/>
<apex:outputField value="{!tsk.Description}" id="Contact"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Call Result" for="tsk.Call_Result__c" style="font-weight:bold"/>
<apex:outputField value="{!tsk.Call_Result__c}" id="Contact"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Due Date" for="tsk.ActivityDate" style="font-weight:bold"/>
<apex:outputField value="{!tsk.ActivityDate}" id="Contact"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageblock>
</apex:repeat>
</apex:form>
</apex:page>
Apex Controller:
public class ActivityHistoryOnContact{
public String currentUser = UserInfo.getUserId();
public String oldUser;
//this oldUser variable is for legacy Users that were imported from a separate instance of SF and had a different id in this old instance.
public String currentContact = ApexPages.currentPage().getParameters().get('id');
public String taskList {get;set;}
public Task[] getListTasks() {
oldUser=[select old_ID__c from User where id=:currentUser limit 1]
[0].old_ID__c;
taskList = 'select whoid,subject,status, ActivityDate, LastModifiedDate, WhatID,Description, Primary_Contact_Phone_Number__c, Primary_Contact_Email_Address__c, Call_Result__c, Last_Call_Date__c, Last_Call_Agent__c from task WHERE (CreatedbyId=\''+currentUser+'\' OR OLDOWNERID__C=\''+oldUser+'\') AND WhoID =\''+currentContact+'\' order by ActivityDate desc limit 20000';
System.debug('~~~~~~'+tasklist);
List<Task> tskList = Database.query(taskList);
return tskList;
}
public ActivityHistoryOnContact(ApexPages.StandardController controller){}
}
Any thoughts as to why seemingly random records are not appearing? I am at a loss, since the records don't seem to have anything in common.