PD1 Developer Fundamentals 4 — Questions and Answers
Question 1: Which Apex collection type enforces uniqueness of its elements and does not maintain insertion order?
- List
- Map
- Set (Correct answer)
- Queue
Correct answer: Set
An Apex Set stores unique values only and does not guarantee any particular ordering of its elements.
Question 2: What is the result of calling String.valueOf(null) in Apex?
- Throws a NullPointerException
- Returns the string 'null' (Correct answer)
- Returns an empty string ''
- Returns the integer 0
Correct answer: Returns the string 'null'
String.valueOf(null) returns the literal string 'null' rather than throwing an exception.
Question 3: In Apex, which access modifier makes a method available to any Apex code in any namespace?
- private
- protected
- public
- global (Correct answer)
Correct answer: global
The global modifier exposes a method to all Apex code across all namespaces, including managed packages.
Question 4: A developer defines 'public virtual class Animal' and 'public class Dog extends Animal'. What is required for Dog to override a method from Animal?
- The method in Animal must be marked 'static'
- The method in Animal must be marked 'virtual' or 'abstract', and Dog must use 'override' keyword (Correct answer)
- No special keywords are needed; all methods are overridable by default
- Dog must use the 'implements' keyword instead of 'extends'
Correct answer: The method in Animal must be marked 'virtual' or 'abstract', and Dog must use 'override' keyword
In Apex, methods can only be overridden if declared virtual or abstract in the parent class, and the subclass must use the override keyword.
Question 5: What does the 'with sharing' keyword enforce in an Apex class?
- The class runs with full System-level access to all records
- The class respects the running user's record-level sharing rules (Correct answer)
- The class shares its data with all users in the org
- The class is shared across multiple Salesforce orgs
Correct answer: The class respects the running user's record-level sharing rules
With sharing enforces the running user's org-wide defaults, role hierarchy, and sharing rules when accessing records.
Question 6: Which statement correctly describes Apex's handling of unhandled exceptions in a trigger?
- The exception is logged silently and the trigger completes partially
- The entire transaction rolls back and the user sees an error message (Correct answer)
- The record is saved, but post-processing is skipped
- The trigger retries automatically up to 3 times
Correct answer: The entire transaction rolls back and the user sees an error message
An unhandled exception in an Apex trigger causes the entire DML transaction to roll back, and Salesforce displays an error to the user.
Question 7: A developer wants to prevent a class from being instantiated directly. Which Apex technique achieves this?
- Marking the class as 'global'
- Making the constructor 'private' (Correct answer)
- Adding the @NoInstantiate annotation
- Marking the class as 'static'
Correct answer: Making the constructor 'private'
A private constructor prevents external code from instantiating the class directly, commonly used in singleton or utility class patterns.
Which Apex collection type enforces uniqueness of its elements and does not maintain insertion order?