Namespaces
By the end of this lesson, you'll be able to:
- Explain what a namespace is and the problem it solves
- Recognize namespace-prefixed names in managed package code
- Understand why most org-native Apex code has no namespace at all
Prerequisites: "Annotations Overview"
The problem: name collisions
Imagine your org has a class called Calculator, and you install a package from another vendor that also defines a class called Calculator. Without something to tell them apart, Salesforce wouldn't know which one any given piece of code means. A namespace solves this — every managed package gets a unique namespace prefix, and its classes are automatically qualified by it.
What a namespaced name looks like
// If a package has namespace "acme", its Calculator class is really:
acme.Calculator calc = new acme.Calculator();
acme.Calculator and your own org's plain Calculator are completely different classes as far as Apex is concerned, even though they share a simple name — the namespace prefix is what tells them apart.
Why your own code usually has no namespace
Code written directly in your own org (not distributed as a managed package) typically has no namespace at all — this is why every class in this course, like EventTicket or CourseRoster, has been referenced by its plain name with no prefix. Namespaces become relevant once you're installing managed packages or building one yourself to distribute — both topics outside this introductory module's scope.
Exercise
As a comment, explain why two classes with the same name — one in your org, one in an installed package — don't conflict with each other.
Show hint
The package's namespace prefix distinguishes them.
Namespaces Quiz
My Notes
Log in to keep private notes on this lesson.
Questions about this lesson
No questions yet — be the first to ask.
Log in to ask a question about this lesson.
Summary
A namespace is a short prefix that keeps names from colliding when code from different sources — your own org and installed packages — coexists in the same Salesforce environment.