Last active
August 29, 2015 14:11
-
-
Save amonshiz/ae27e127fcbaf333403d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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