Scenario The support director reviews escalations every week. She wants to see which customers have raised urgent problems recently, together with the actual Cases, so the account team can follow up.
Task
Write one SOQL query on Account that:
Priority = 'High' created in the last 30 days (LAST_N_DAYS:30).CaseNumber and Subject.Expected output
One row per qualifying Account with Id, Name and a nested Cases list containing CaseNumber and Subject. Row order does not matter.
Example Account Acme has a High Case from 5 days ago (Subject Outage) and a Medium Case from 3 days ago. Account Globex has a High Case from 90 days ago. Account Initech has no Cases.
Use a single query on Account: a parent-to-child subquery on the Cases relationship for the case list and a semi-join (Id IN) to exclude Accounts without matching Cases. Use the LAST_N_DAYS date literal, not a hardcoded date. Apply the same two Case filters inside the subquery and inside the semi-join.
10 row(s), any order
| # | Id | Name | Cases |
|---|---|---|---|
| 1 | 001000000000009AAA | Account 9 | [1 record] |
| 2 | 001000000000014AAA | Account 14 | [1 record] |
| 3 | 001000000000005AAA | Account 5 | [1 record] |
| 4 | 001000000000002AAA | Account 2 | [1 record] |
| 5 | 001000000000017AAA | Account 17 | [1 record] |
| 6 | 001000000000003AAA | Account 3 | [1 record] |
| 7 | 001000000000011AAA | Account 11 | [1 record] |
| 8 | 001000000000008AAA | Account 8 | [1 record] |
| 9 | 001000000000020AAA | Account 20 | [1 record] |
| 10 | 001000000000006AAA | Account 6 | [1 record] |