I have the below Apex class to query for EmailMessages tied up with the Case object.
public with sharing class CaseEmailExtension {
public ID csId {get; set;}
public CaseEmailExtension() {}
private final Case currentCase;
public CaseEmailExtension(ApexPages.StandardController currentcase) {
this.currentCase = (Case)currentcase.getRecord();
}
public List<EmailMessage> getSortEmails(){
return this.csId == null
? new List<EmailMessage>() // handles UI preview use case
: [SELECT Id, FromAddress, ToAddress, BCCAddress, CcAddress, MessageDate, Subject, Incoming, HtmlBody, CreatedBy.Name
from EmailMessage where ParentId =: this.csId
order by MessageDate DESC ];
}
}
I would like to extract only the EmailMessages in which the Case Contact was involved as either To, Cc, or Bcc.
I am struggling with tweaking the SOQL query to reference the above condition.
Thank you.