Exam PDI Topic 2 Question 116 Discussion
Actual exam question for Salesforce's PDI exam
Question #: 116
Topic #: 2
Question #: 116
Topic #: 2
A developer has an integer variable called maxAttempts. The developer needs to ensure that once maxAttempts is initialized, it preserves its value for the length of the Apex transaction; while being able to share the variable's state between trigger executions.
How should the developer declare maxAttempts to meet these requirements?
How should the developer declare maxAttempts to meet these requirements?
Suggested Answer: D Vote an answer
To preserve the value of maxAttempts for the length of the Apex transaction and share its state between trigger executions:
* Static Variable:
* Static variables are initialized once per transaction and retain their value throughout the transaction.
* They can be accessed without instantiating the class.
* Private Scope:
* Declaring it as private ensures encapsulation and prevents unintended external modification.
* Helper Class:
* Using a helper class ensures the separation of concerns, keeping trigger logic clean and adhering to best practices.
Example Code:public class HelperClass {
private static Integer maxAttempts = 5; // Default value
public static Integer getMaxAttempts() {
return maxAttempts;
}
public static void setMaxAttempts(Integer attempts) {
maxAttempts = attempts;
}
}
* A: Constants (static + final) cannot be modified after initialization.
* B: Trigger member variables cannot retain values across executions within the same transaction.
* C: Declaring it as a non-static variable in a helper class would reset its value during each trigger execution.
Why Not the Other Options?
* Static Variable:
* Static variables are initialized once per transaction and retain their value throughout the transaction.
* They can be accessed without instantiating the class.
* Private Scope:
* Declaring it as private ensures encapsulation and prevents unintended external modification.
* Helper Class:
* Using a helper class ensures the separation of concerns, keeping trigger logic clean and adhering to best practices.
Example Code:public class HelperClass {
private static Integer maxAttempts = 5; // Default value
public static Integer getMaxAttempts() {
return maxAttempts;
}
public static void setMaxAttempts(Integer attempts) {
maxAttempts = attempts;
}
}
* A: Constants (static + final) cannot be modified after initialization.
* B: Trigger member variables cannot retain values across executions within the same transaction.
* C: Declaring it as a non-static variable in a helper class would reset its value during each trigger execution.
Why Not the Other Options?
by Arun at Jul 24, 2026, 06:50 AM
0
0
0
10
Comments
Arun
2026-07-24 06:50:56Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
Report Comment
Commenting
You can sign-up / login (it's free).