SF-PD2 Advanced Developer Fundamentals Practice Question
Exhibit
{
"apex_code": "public void updateAccount(Id accId) {
Account acc = [SELECT Id, Name FROM Account WHERE Id = :accId];
acc.Name = 'New Name';
update acc;
}"
}Refer to the exhibit. The developer needs to update this code to be more robust. What is the most critical issue to address in this code snippet?
⚠ Common exam trap
Candidates often assume the query will always return a record, failing to account for the 'List has no rows for assignment' runtime exception when the ID is invalid or missing.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
The code will fail with an exception if the ID does not exist.
The current code lacks a check for whether the account exists before accessing or updating it. If the query returns no records, it will throw a 'List has no rows for assignment to SObject' exception. Robust code should handle this possibility by checking for null or using a list to retrieve the record safely, ensuring the application remains resilient even when data is missing.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
The code is not bulkified to handle a list of IDs.
Why it's wrong here
While the code is not bulkified, the immediate risk is the runtime exception caused by assigning a null result to an SObject variable. Addressing the 'no rows' exception is the priority for code reliability. While bulkification is a best practice, it is secondary to preventing a crashing exception during standard execution.
- ✓
The code will fail with an exception if the ID does not exist.
Why this is correct
When an SOQL query is assigned to a single SObject variable, Salesforce expects exactly one result. If zero results are returned, a runtime exception occurs. Using a List to query the data allows the developer to check if the list is empty before attempting an update, avoiding the crash.
- ✗
The code does not use 'with sharing' to enforce security.
Why it's wrong here
Although enforcing sharing is a best practice for security, the most critical issue here is the stability of the application. An exception that crashes the transaction is more dangerous than an incorrect sharing context. Once the code is stable, security can be addressed as the next step in development.
- ✗
The code uses hardcoded string values for the name.
Why it's wrong here
While hardcoding values is not ideal, it does not cause a functional failure or a runtime exception. The primary issue is the potential for a 'List has no rows' error, which disrupts system operations. Refactoring the hardcoded string should be deferred until the fundamental reliability of the database interaction is secured.
About these practice questions
This SF-PD2 question is part of Courseiva's 226-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written and reviewed by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
Last reviewed September 2026 · checked against the official Salesforce exam blueprint
This SF-PD2 practice question is part of Courseiva's free Salesforce certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the SF-PD2 exam.