2

I need to be able to query for a set of Cases by things like Country or Subject, but also by searching the contents of all its Comments. The only ways I can think of to do this with CaseComments are:

  1. Query the case comments and get case IDs, then search this subset of cases.
  2. Query the cases with the other parameters, then search the comments of each case.
  3. Query both the cases and the comments, then perform a comparison on the case IDs in each subset.

All of these solutions feel like they are inefficient and that there should be a better way of doing it. Is there? What method should I use to get the result set that I want?

1

Whenever we have to query multiple objects like in your case you need to query Case and Case comments prefer SOSL to query efficiently.

There is already a great reference to understand the difference between soql and sosl in below link when to use SOSL and SOQL

So a SOSL on the case and case comments will be needed .

Let me run through a how to use developer console for SOSL.Great news is we can use developer console of for writing the SOSL query

Here is the sample query.Please modify as you needed

FIND {hello*} IN ALL FIELDS RETURNING case(Id,CaseNumber),casecomment(ParentId,CommentBody,Parent.CaseNumber)

The screenshot of how the result looks like

enter image description here

UPDATE:

This is how the query will include where clause

FIND {hello*} IN ALL FIELDS RETURNING case(Id,CaseNumber where createddate<TODAY),casecomment(ParentId,CommentBody,Parent.CaseNumber where ParentID!=null) 
2
  • Thank you for your response. This appears to do part of what I'm looking for, but how can I simultaneously filter the results down by things such as CreatedDate, as I would by using "WHERE" clauses in SOQL? Is this possible to do with only one query? @Mohith Kumar Nov 25 '13 at 20:09
  • You can include where clause .Just check my updated answer .Also upvote and Mark as answered if it answers your question Nov 26 '13 at 4:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.