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
Manpreet Singh 13Manpreet Singh 13 

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>
Surendra nuneSurendra nune
Have you tried specifying the date format correctly?
{0,date,dd.MM.yyyy HH:mm:ss z}  // without any quotes in between
Manpreet Singh 13Manpreet Singh 13
Just now tried, it is not working. Here is my current output.

User-added image
Manpreet Singh 13Manpreet Singh 13
I am not very sure, how to bring other field like Email Subject, Email body, Too, CC, BCC, From etc on to the visualforce page. 
Alok Khandelwal - DamcoAlok Khandelwal - Damco
Hi Manpreet,

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:
 
<apex:pageBlockTable value="{!mappingRowsList}" var="map" columns="6" columnsWidth="20%,20%,15%,10%,15%,20%" width="100%">  
              <apex:column >
                 <apex:facet name="header">Target Object Field</apex:facet>
                 <apex:selectList disabled="true" value="{!map.selectedTargetField}" multiselect="false" size="1">
                            <apex:selectOptions value="{!map.targetFields}"/>
                        </apex:selectList>  
                    </apex:column> 
                     <apex:column >
                        <apex:facet name="header">Target Field Type</apex:facet>
                        <apex:outputLabel value="{!map.fieldType}"/>
                    </apex:column> 
                    <apex:column >
                        <apex:facet name="header">Source Object Fields</apex:facet>
                        <apex:selectList value="{!map.selectedSourceField}" multiselect="false" size="1">
                            <apex:selectOptions value="{!map.sourceFields}"/>
                        </apex:selectList>  
                    </apex:column>
                    <apex:column >
                        <apex:facet name="header">Is Value Map</apex:facet>
                        <apex:inputCheckbox value="{!map.isValueMap}"/>
                    </apex:column>                     
                    <apex:column >
                        <apex:facet name="header">Enter Value</apex:facet>
                        <apex:inputText rendered="{!map.fieldType != 'PICKLIST'}" value="{!map.inputValue}"/>                        
                    </apex:column>                    
      </apex:pageBlockTable>

I hope it was helpful.

Regards,
Alok