The requirement is to pull the CommentBody field from CaseComments and TextBody field from EmailMessages and display them in a single column in a table. The other column should contain the created date/time. The records have to be arranged in a chronological order.
A Case contains several comments and emails. I'm able to create two tables, one for CaseComments and the other for EmailMessages and I've tried to combine these two into one table by creating a wrapper class but I couldn't complete it.
This is the code. I apologize, there are many errors in this code. This wrapper class might work if there is only one comment and email. As I'm not sure how to loop the comments, emails and the created date/time. And in the visualforce how to pull the comments/emails in one column and date/time in the adjacent column in DESC order. It would be really helpful to direct me on this. Thanks in advance.
public Class CaseInteraction {
private Case c;
public List<CaseWrap> casewrapper {get; set;}
public Class CaseWrap {
public CaseComment casecom {get; set;}
public EmailMessage emailms {get; set;}
}
public CaseInteraction (ApexPages.StandardController con) {
this.c = (Case) con.getRecord();
casewrapper = new List<CaseWrap>();
CaseComment cc = [SELECT id, commentBody, createdDate, createdById, isPublished FROM CaseComment WHERE ParentId=:c.Id ORDER BY createdDate DESC];
EmailMessage em = [SELECT id, Subject, TextBody, CreatedDate FROM EmailMessage WHERE ParentId=:c.Id ORDER BY createdDate DESC];
CaseWrap ccem = new CaseWrap()
ccem.casecom = cc;
ccem.emailms = em;
casewrapper.add(ccem);
}
Rest of the Controller
}
PAGE:
<apex:pageBlock >
<apex:facet name="header"><span class="ttitle"> Interaction </span></apex:facet>
<apex:pageBlockSection collapsible="false" columns="1">
<apex:pageBlockTable value="{!casewrapper}" var="cw" >
<apex:column value="{!cw.ccem}" headerValue="Message" />
<apex:column value="{!cw.CreatedDate}" width="300px" headerValue="Date/Time Sent" />
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock >
<!-- Rest of the Page -->
</apex:page>
Edit:
May be I've brought up a wrong approach in the code. Concatenating is not my intention. A column should have the content of both Casecomments and EmailMessages in individual rows (with it's created date in the neighbor column). Like:
Table
Message(col) Created Date(col)
comment3 05/26/2014
email2 05/25/2014
comment2 05/24/2014
email1 05/23/2014
comment1 05/22/2014
CaseComments
andEmailMessages
for a givenCase
, how do you intend to match aCaseComment
to anEmailMessage
? Or is your intent to concatenate all comment bodies and message bodies into one long string?