/*
* @Description: APEX Server Side Controller.
* Provides methods to fetch case and work with case from Community
*/
public class CommunityCaseDisplayController {
@AuraEnabled
public static List<CaseComment> getCaseComments(String caseId) {
List<CaseComment> caseComments =
[SELECT Id, ParentId, IsPublished, CommentBody, CreatedDate, CreatedBy.Name, LastModifiedDate, LastModifiedById FROM CaseComment where parentId=:caseId order by CreatedDate desc];
return caseComments;
}
@AuraEnabled
public static CaseComment addCaseComment(String caseId, String commentBody) {
CaseComment caseComment = new CaseComment(ParentId=caseId, CommentBody=commentBody);
insert caseComment;
return caseComment;
}
}
Hi Andrew,For above APEX class, your test class looks like below:@isTestpublic class CommunityCaseDisplayControllerTest { @isTest static void test_method(){ Account acc = new Account (name='ABC Test'); insert acc; Case c = new case (); c.Accountid = acc.Id; c.Status = 'New'; insert c; Test.startTest(); CaseComment caseComment = CommunityCaseDisplayController.addCaseComment(c.Id, 'Testing for Class'); List<CaseComment> lCC = CommunityCaseDisplayController.getCaseComments(c.Id); Test.stopTest(); }}Hope this help. Please mark it as best answer if it resolves your issue.Thanks!!