Static keyword

The static keyword in Apex is used to define class-level variables and methods.

  • It is used to avoid Recursion
  • Reset only per transaction
  • Static can be only class variables

Calling From Calling To Allowed? Example
Static Static ✔ Yes Utility → Utility
Static Non-Static ❌ No static → instance not allowed unless creating object
Non-Static Static ✔ Yes instance → class
Non-Static Non-Static ✔ Yes instance → instance

Share