# Write a SOQL query to fetch all Case records that have been escalated and have at least one CaseComment created by a Customer Community User.

**Topic:** Development · **Difficulty:** Hard · **Asked at:** Cognizant, Capgemini, HCL · **Tags:** soql, scenario, semi-join, experience-cloud

Read it on the site: https://www.forcechallenges.com/interview-questions/write-a-soql-query-to-fetch-all-case-records-that-have-been-escalated-and-have-at-least-one-casecomment

## Answer

Use a semi-join on `CaseComment` restricted to comments created by Experience Cloud (community) users, combined with the escalation flag.

```soql
SELECT Id, CaseNumber, Subject FROM Case
WHERE IsEscalated = true
  AND Id IN (SELECT ParentId FROM CaseComment
             WHERE CreatedBy.UserType IN ('CspLitePortal', 'PowerCustomerSuccess', 'CustomerSuccess'))
```
The `UserType` values identify Customer Community and Customer Community Plus users; check the exact values used in your org.

---
Source: ForceChallenges · last updated 2026-10-19
