Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to know if there is an idea of very base Object class in Apex, like we have it in Java or C#. Seem like it's supported, for example I can write something like the following in developer console and it works:

List<Object> test = new List<Object> {1, 'a'};

But I can't find any documentation about it. Does anyone know if it's officially supported?

share|improve this question
up vote 17 down vote accepted

There is a system class called Object that is the base for every other construct in the system. This class is completely useless except as a "void pointer" to other types of data. For example, we can store any type of data in an object, and we can use instanceof to retrieve the base type of the object.

static void dosomething(object source) {
    if(source == null) {
    if(source instanceof integer) {
    if(source instanceof map<string, integer>) {
    ... etc

It appears to support two functions: hashcode() and equals(object). However, calling either method appears to crash the code and/or cause unexpected results (but they do compile and run). It is safe to use the standard equality operators, ==, !==, ===, and !==. You can safely use Object as a key or value in a map, set, or list. You cannot construct an object, as it is most likely defined as abstract.

There is no documentation on this class that I've ever seen; it's mentioned in various parts of the documentation, but only ever as a placeholder for generic type interfaces. Note that the compiler internally refers to this type as ANY. It's only as functional as it needs to be to allow polymorphic code.

share|improve this answer
@minige, an example place in the doc where it is used is the example for JSON.deserializeUntyped() – cropredy Jul 8 '14 at 18:10
Thanks, @sfdcfox – minige Jul 8 '14 at 19:03

I think what you want is sObject. That's the closest you'll get in Apex. It's not a base class to all objects though. It's just a base class for the Salesforce built-in objects and custom objects.

More here

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.