You need to sign in to do that
Don't have an account?
jagdish nikam
Static Keyword in trigger
Why we don't use static keyword in trigger? i am new to the salesforce. i know little bit about statc keyword but want answer in this case.
function readOnly(count){ }
You need to sign in to do that
Don't have an account?
You can use static variables in trigger however they are not usually recommended. Some of the main reasons behind this is
- It is bad practice to write logic inside your trigger, minimizing the amount of code in a trigger and instead implement all functionality in class.
- Having static variables separated in a class will help you with the unit test by loading up the static variables with the required data and not rely on the fact that you have to trigger the trigger in order to populate with test data test your scenario.
- Also the most important thing to know about triggers is that when you have more than one trigger of the same type, you cannot predict the order in which they will fire. So if you have a static variable in a trigger that has a value that another trigger will depend on than you would have some problems.
If my post was of any help please like it, if it answers your question please mark it as solution.All Answers
You can use static variables in trigger however they are not usually recommended. Some of the main reasons behind this is
- It is bad practice to write logic inside your trigger, minimizing the amount of code in a trigger and instead implement all functionality in class.
- Having static variables separated in a class will help you with the unit test by loading up the static variables with the required data and not rely on the fact that you have to trigger the trigger in order to populate with test data test your scenario.
- Also the most important thing to know about triggers is that when you have more than one trigger of the same type, you cannot predict the order in which they will fire. So if you have a static variable in a trigger that has a value that another trigger will depend on than you would have some problems.
If my post was of any help please like it, if it answers your question please mark it as solution.