You need to sign in to do that
Don't have an account?

combine two queries on case
is it possible to combine below two queries as one, where I need to display Case emails and comments in a page pertaining to a case order by createddate desc
List <EmailMessage> sortedEmails = new List<EmailMessage>(); sortedEmails = [SELECT Id, FromAddress, ToAddress, BCCAddress, MessageDate, Subject, HasAttachment, Incoming, TextBody, CreatedBy.Name from EmailMessage where ParentId =: currentCase.Id order by MessageDate DESC ]; List<CaseComment> Casecomments = new List<CaseComment>(); Casecomments = [SELECT Id, CommentBody, CreatedDate, ParentId FROM CaseComment where ParentId =: currentCase.Id order by CreatedDate DESC];
There is not relationshp between CaseComment and EmailMessage so you can't combine in single query.
I will suggest user Create Wrapper class like
convert this EmailCaseCommmentByParentId map to list.
Please mark this as best if it helps to you.
Regards,
Prakash
nawaleprakash@gmail.com
Many thanks.
unbale to figure it out, not working for my requirment
I am struck how to use above code to display realted emails and casecomments pertaiining to a case in descending order by createddate/emailmessage