This question runs in a pre-configured Salesforce environment - no personal connection required.

Query all Contact records that are not associated with an Account (AccountId is null). For each such Contact, build the full name by concatenating FirstName and LastName with a single space between them. If FirstName is null, use an empty string in its place and trim the resulting full name. Return the list of full names sorted alphabetically in ascending order. Return an empty list if no orphan contacts exist.

Examples:

Input: (no parameters - operates on org data) Scenario: Two contacts with null AccountId exist Contact 1: FirstName = John, LastName = Doe Contact 2: FirstName = Alice, LastName = Smith Output: ['Alice Smith', 'John Doe'] Explanation: Names are sorted alphabetically ascending Scenario: No contacts have null AccountId Output: [] Explanation: Return empty list when no orphan contacts exist Scenario: Contact with null FirstName and null AccountId Contact: FirstName = null, LastName = Johnson Output: ['Johnson'] Explanation: Null FirstName is treated as empty string, then the full name is trimmed Scenario: Multiple orphan contacts with same last name Contact 1: FirstName = Anna, LastName = Brown Contact 2: FirstName = Brian, LastName = Brown Output: ['Anna Brown', 'Brian Brown'] Explanation: When last names match, first names determine alphabetical order
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 account

How 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 June 2026

Contest runs June 1 - 30. Complete challenges to climb the leaderboard!

Only the 30 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.

Wally can't hear you

Please sign in to access the AI Assistant

Sign In