A Developer Edition org has five existing accounts. A developer wants to add 10 more accounts for testing purposes.
The following code is executed in the Developer Console using the Execute Anonymous window:

How many total accounts will be in the org after this code is executed?
Correct Answer: D
The code snippet in question creates and inserts an account namedMyAccountand then initializes a loop to add additional accounts.
The loop runs fromx = 1and continues adding accounts untilx < 10.
Since the conditionx++is post-increment, the loop runs exactly 10 times, creating and adding 10 new accounts to thenewAccountslist.
At the end, theinsertDML statement persists these 10 new accounts, along with the already existing account (MyAccount).
Total accounts in the org:
Existing accounts = 5
New accounts added = 10
Total = 15
Salesforce Apex Developer Guide
Salesforce SOQL & SOSL Reference
Recent Comments (The most recent comments are at the top.)
B. 6
Explanation: We only did insert once (insert My account;), the do loop populates the list but doesnt INSERT !