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!
Create an Account
Sign up to track your progress, earn points, and compete with others. Your solutions will be saved automatically.
Create accountHow It Works
- • Write your solution in the code editor
- • Connect your Salesforce org to test
- • Submit to check if your solution passes
- • Use hints if you get stuck
Contest Alert
🏆 #CodeEveryDay Mar 2026
Contest runs March 3 - 31. Complete challenges to climb the leaderboard!
Points are calculated for challenges completed during the contest period.