Skip to content

Instantly share code, notes, and snippets.

@amonshiz
Last active August 29, 2015 14:11
Show Gist options
  • Save amonshiz/ae27e127fcbaf333403d to your computer and use it in GitHub Desktop.
Save amonshiz/ae27e127fcbaf333403d to your computer and use it in GitHub Desktop.
<apex:component controller="CaseCommentsComponentController" selfClosing="true">
<apex:attribute name="accountId" description="The ID of the Account to reference" type="Id" required="false" assignTo="{!theAccountId}"></apex:attribute>
<apex:pageBlock>
<apex:pageBlockSection>
<apex:pageBlockTable value="{!comments}" var="c">
<apex:column value="{!c.Parent.CaseNumber}" />
<apex:column value="{!c.Parent.Subject}" />
<apex:column value="{!c.CommentBody}" />
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:component>
public with sharing class CaseCommentsComponentController {
public CaseCommentsComponentController() {}
public Id theAccountId { get; set; }
public List<CaseComment> comments {
get {
if (comments == null) {
comments = new List<CaseComment>();
Set<Id> caseIds = new Set<Id>();
for (CaseComment cc : [SELECT Id, ParentId, Parent.CaseNumber, Parent.Subject, CommentBody, CreatedDate
FROM CaseComment
WHERE ParentId IN (SELECT Id FROM Case WHERE AccountId = :theAccountId)
ORDER BY ParentId ASC, CreatedDate DESC]) {
if (!caseIds.contains(cc.ParentId)) {
caseIds.add(cc.ParentId);
comments.add(cc);
}
}
}
return comments;
}
private set;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment