A developer has written an After Update trigger on Account. A workflow rule and field update cause the trigger to repeatedly update the Account records. How should the developer handle the recursive trigger?
A.
Deactivate the trigger and move the logic into a Process or Flow
B.
Deactivate the workflow rule to prevent the field update from executing
C.
Use a static variable to prevent the trigger from executing more than once
D.
Use a global variable to prevent the trigger from executing more than once
Deactivating the workflow rule would remove the logic that may still be needed. Moving it to flows and process builders could work but there are other options that would be easier to implement. A global variable is too broad.
A static variable will hold the value during the run of all processes that are triggered (during the threaded call) and will maintain its value in the context of this process.
A static variable is static only within the scope of the Apex transaction. It’s not static across the server or the entire organization. The value of a static variable persists within the context of a single transaction and is reset across transaction boundaries. For example, if an Apex DML request causes a trigger to fire multiple times, the static variables persist across these trigger invocations.
To store information that is shared across instances of a class, use a static variable. All instances of the same class share a single copy of the static variable. For example, all triggers that a single transaction spawns can communicate with each other by viewing and updating static variables in a related class. A recursive trigger can use the value of a class variable to determine when to exit the recursion.
upvoted 2 times
...
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting 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.
Sapphire808
1 year, 1 month agoLiquad
3 years, 2 months ago