To preserve the value ofmaxAttemptsfor 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?