Salesforce Platform Developer I (legacy) — Question 88

Given the following Apex statement:
Account myAccount = [SELECT Id, Name FROM Account];
What occurs when more than one Account is returned by the SOQL query?

Answer options

Correct answer: D

Explanation

When a SOQL query retrieves more than one record but is assigned to a single variable, it results in an unhandled exception. This is because the code expects only one Account, and receiving multiple records violates this expectation, causing the execution to terminate.