Scenario The customer-success team wants to reach out to people at customers who are still in the middle of their first purchase. These are Accounts that currently have a deal in progress but have never closed a won deal with the company.
Task
Write one SOQL query on Contact that returns Contacts whose Account:
IsClosed = false), andIsWon = true).Sort the result by the Account name, then by the Contact's last name.
Expected output
One row per Contact with the columns Id, Name and Account.Name.
Example
Use one query on Contact that combines a semi-join (AccountId IN) on open Opportunities with an anti-join (AccountId NOT IN) on won Opportunities. Read the account name through Account.Name. Order by Account.Name, then LastName.
8 row(s), order checked
| # | Id | Name | Account.Name |
|---|---|---|---|
| 1 | 003000000000015AAA | First 15 Contact 15 | Account 1 |
| 2 | 003000000000030AAA | First 30 Contact 30 | Account 1 |
| 3 | 003000000000001AAA | First 1 Contact 1 | Account 2 |
| 4 | 003000000000016AAA | First 16 Contact 16 | Account 2 |
| 5 | 003000000000017AAA | First 17 Contact 17 | Account 3 |
| 6 | 003000000000002AAA | First 2 Contact 2 | Account 3 |
| 7 | 003000000000018AAA | First 18 Contact 18 | Account 4 |
| 8 | 003000000000003AAA | First 3 Contact 3 | Account 4 |