This question runs in a pre-configured Salesforce environment - no personal connection required.
Write a method that returns a list of Account names that do not have any associated Contact records. The results should be sorted alphabetically by Account name.
Use a SOQL subquery with the NOT IN clause to identify accounts without contacts.
Method Signature
public static List<String> getAccountsWithoutContacts()
Examples
Example 1:
Input: Org has accounts: "Acme Corp" (2 contacts), "Beta Inc" (0 contacts), "Gamma LLC" (1 contact)
Output: ["Beta Inc"]
Explanation: Only Beta Inc has no related contacts
Example 2:
Input: All accounts in the org have at least one contact
Output: []
Explanation: No orphan accounts exist
Example 3:
Input: Org has accounts: "Alpha Co", "Zeta Corp", "Delta Ltd" (none have contacts)
Output: ["Alpha Co", "Delta Ltd", "Zeta Corp"]
Explanation: All three accounts have no contacts, sorted alphabetically
Apex Code Editor
Welcome to Lightning Challenge!
How It Works
- • Write your solution in the code editor
- • This challenge runs without connecting your own org
- • Submit to check if your solution passes
- • Use hints if you get stuck
Contest Alert
🏆 #CodeEveryDay July 2026
Contest runs July 1 - 31. Complete challenges to climb the leaderboard!
Only the 31 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.