You need to sign in to do that
Don't have an account?

Need help with Apex class
Created Apex class to show Case Tasks and Case Emails in chronological order on visualforce page. The problem is that I am not able to show fields on visualforce page, not sure where I am going wrong. Any help/pointers would be appreciated
Here is the Apex Class code
global with sharing class CaseEmailExtension {
private final Case currentCase;
public CaseEmailExtension(ApexPages.StandardController currentcase) {
this.currentCase = (Case)currentcase.getRecord();
}
global class commoncontainer implements Comparable {
public DateTime createdDate{get;set;}
public String content{get;set;}
global Integer compareTo(Object compareTo) {
commoncontainer compareToEmp = (commoncontainer)compareTo;
if (createddate== compareToEmp.createddate) return 0;
if (createddate> compareToEmp.createddate) return 1;
return -1;
}
}
public List<commoncontainer> getSortcommoncontainer(){
List <commoncontainer> containerlist = new List<commoncontainer>();
for(EmailMessage emailmsg : getsortEmails())
{
CommonContainer cc=new CommonContainer();
cc.createdDate=emailmsg.CreatedDate;
cc.content='Subject:' + emailmsg.CreatedDate + 'From:' + emailmsg.FromAddress + 'To:' + emailmsg.ToAddress + 'BCC:' + emailmsg.BCCAddress + 'Subject:' + emailmsg.Subject + 'EmailBody:' + emailmsg.TextBody + 'CreatedBy:' + emailmsg.CreatedBy.Name;
containerList.add(cc);
}
for(Attachment att: getattachments())
{
CommonContainer cc=new CommonContainer();
cc.createdDate=att.CreatedDate;
cc.content='Name:' + att.Name + 'Created By:' + att.CreatedBy.name;
containerList.add(cc);
}
for(Task task: gettask())
{
CommonContainer cc=new CommonContainer();
cc.createdDate=task.CreatedDate;
cc.content='Assigned To:' + task.Who.Name + 'Created By:' + task.CreatedBy.name + 'Status:' + task.Status + 'Priority:' + task.Priority + 'Due Date:' + task.ActivityDate + 'Subject:' + task.Subject + 'Description' + task.Description;
containerList.add(cc);
}
containerlist.sort();
return containerlist;
}
public List<EmailMessage> getSortEmails(){
List <EmailMessage> sortedEmails = new List<EmailMessage>();
sortedEmails = [SELECT Id, FromAddress, ToAddress, BCCAddress, CreatedDate, Subject, HasAttachment, Incoming, TextBody, CreatedBy.Name
from EmailMessage where ParentId =: currentCase.Id
order by MessageDate DESC ];
return sortedEmails;
}
public List<Task> getTask() {
List<Task> Task= new List<Task>();
Task = [SELECT Id, Priority, Subject, Status, Description, CreatedDate, ActivityDate, CreatedBy.Name,Who.Name
from Task order by CreatedDate DESC];
return Task;
}
}
Here is the Visualforce Page code
<apex:page standardController="Case" showHeader="false" sidebar="false" title="Case Number: {!Case.CaseNumber}" extensions="CaseEmailExtension">
<apex:form >
<apex:pageBlock title="Case Number: {!Case.CaseNumber}">
<apex:pageBlockButtons location="top" >
<apex:CommandButton value="Print" onclick="javascript:window.print(); return false"/>
<apex:CommandButton value="Close" onclick="window.close(); return false;"/>
</apex:pageBlockButtons>
<apex:repeat value="{!sortCommonContainer}" var="cc">
<apex:pageblock >
<apex:facet name="header">
<apex:outputText value="{0,date,dd'.'MM'.'yyyy HH:mm:ss z}" style="font-weight:bold;font-style:italic;font-size:12px;float:left ">
<apex:param value="{!cc.CreatedDate}" />
</apex:outputText>
</apex:facet>
<td width="100%" align="left">
<table cellpadding="2px">
<tr>
</tr>
</table>
</td>
</apex:pageblock>
</apex:repeat>
</apex:form>
</apex:page>
Here is the Apex Class code
global with sharing class CaseEmailExtension {
private final Case currentCase;
public CaseEmailExtension(ApexPages.StandardController currentcase) {
this.currentCase = (Case)currentcase.getRecord();
}
global class commoncontainer implements Comparable {
public DateTime createdDate{get;set;}
public String content{get;set;}
global Integer compareTo(Object compareTo) {
commoncontainer compareToEmp = (commoncontainer)compareTo;
if (createddate== compareToEmp.createddate) return 0;
if (createddate> compareToEmp.createddate) return 1;
return -1;
}
}
public List<commoncontainer> getSortcommoncontainer(){
List <commoncontainer> containerlist = new List<commoncontainer>();
for(EmailMessage emailmsg : getsortEmails())
{
CommonContainer cc=new CommonContainer();
cc.createdDate=emailmsg.CreatedDate;
cc.content='Subject:' + emailmsg.CreatedDate + 'From:' + emailmsg.FromAddress + 'To:' + emailmsg.ToAddress + 'BCC:' + emailmsg.BCCAddress + 'Subject:' + emailmsg.Subject + 'EmailBody:' + emailmsg.TextBody + 'CreatedBy:' + emailmsg.CreatedBy.Name;
containerList.add(cc);
}
for(Attachment att: getattachments())
{
CommonContainer cc=new CommonContainer();
cc.createdDate=att.CreatedDate;
cc.content='Name:' + att.Name + 'Created By:' + att.CreatedBy.name;
containerList.add(cc);
}
for(Task task: gettask())
{
CommonContainer cc=new CommonContainer();
cc.createdDate=task.CreatedDate;
cc.content='Assigned To:' + task.Who.Name + 'Created By:' + task.CreatedBy.name + 'Status:' + task.Status + 'Priority:' + task.Priority + 'Due Date:' + task.ActivityDate + 'Subject:' + task.Subject + 'Description' + task.Description;
containerList.add(cc);
}
containerlist.sort();
return containerlist;
}
public List<EmailMessage> getSortEmails(){
List <EmailMessage> sortedEmails = new List<EmailMessage>();
sortedEmails = [SELECT Id, FromAddress, ToAddress, BCCAddress, CreatedDate, Subject, HasAttachment, Incoming, TextBody, CreatedBy.Name
from EmailMessage where ParentId =: currentCase.Id
order by MessageDate DESC ];
return sortedEmails;
}
public List<Task> getTask() {
List<Task> Task= new List<Task>();
Task = [SELECT Id, Priority, Subject, Status, Description, CreatedDate, ActivityDate, CreatedBy.Name,Who.Name
from Task order by CreatedDate DESC];
return Task;
}
}
Here is the Visualforce Page code
<apex:page standardController="Case" showHeader="false" sidebar="false" title="Case Number: {!Case.CaseNumber}" extensions="CaseEmailExtension">
<apex:form >
<apex:pageBlock title="Case Number: {!Case.CaseNumber}">
<apex:pageBlockButtons location="top" >
<apex:CommandButton value="Print" onclick="javascript:window.print(); return false"/>
<apex:CommandButton value="Close" onclick="window.close(); return false;"/>
</apex:pageBlockButtons>
<apex:repeat value="{!sortCommonContainer}" var="cc">
<apex:pageblock >
<apex:facet name="header">
<apex:outputText value="{0,date,dd'.'MM'.'yyyy HH:mm:ss z}" style="font-weight:bold;font-style:italic;font-size:12px;float:left ">
<apex:param value="{!cc.CreatedDate}" />
</apex:outputText>
</apex:facet>
<td width="100%" align="left">
<table cellpadding="2px">
<tr>
</tr>
</table>
</td>
</apex:pageblock>
</apex:repeat>
</apex:form>
</apex:page>
You need to use PageBlockTable to display the relevant content.You can bind that with the desired object list:
Here is the sample code for you:
I hope it was helpful.
Regards,
Alok