Salesforce Dictionary - Free Salesforce GlossarySalesforce Dictionary
Salesforce Developer
medium

What are the differences between static, instance, and global methods in Apex?

Apex methods have a class scope and a visibility scope.

Class scope:

  • Instance method — bound to an object instance. Access via myObj.method(). Can use instance variables.
  • Static method — class-level. Access via MyClass.method(). No this. Used for utilities and stateless logic.

Visibility scope:

  • `private` — visible only within the class (default).
  • `protected` — visible to the class and its subclasses.
  • `public` — visible to any class in the same namespace.
  • `global` — visible to any code, including code in other namespaces (other Salesforce orgs / managed packages). Required for web service methods, batch start/execute/finish, and methods called from outside your namespace.

When to use each:

  • `private` + instance — most internal class methods.
  • `public` + static — utility methods callable from anywhere in your namespace.
  • `global` — only when truly necessary. global methods are part of your public API and changing their signature breaks consumers — they're effectively eternal commitments. Most code shouldn't be global.

Common mistake: making everything global "just in case". This locks the API permanently. Use public until you have a concrete reason to expose to other namespaces.

Why this answer works

Tests Apex modifier fluency. The "global is a permanent commitment" warning is the strongest signal of someone who's maintained a managed package or shared library.

Follow-ups to expect

Related dictionary terms