+ Start a Discussion
ThisIsRSNThisIsRSN 

How "Type: Object" is used in Salesforce

Hi ,

 

I am curious to know which method for "type: object" are supported in salesforce.

What its use and how it can be leaveraged in salesforce.

 

Thanks

_RSN

 

 

Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox

Object is analogous to Java's java.lang.Object. However, unlike java.lang.Object, it has no static or instance methods or properties. In other words, it can only be used as a dynamic data type that can refer to any other type. Any data type may be implicitly stored as an object (no casting required), but requires a cast to convert the object to any other data type. Most of the valueof static methods support object as a parameter, and the operators ==, !=, ===, and instanceof support objects as operands.

 

You can do the following things with Object:

 

Object a = 5, b = 7, c = 5;
System.assert(a != b);
System.assert(a == c);
System.assert(a != null);
System.assert(a instanceof Integer);
System.assert(String.valueOf(a) == '5');
System.assert(35 == (Integer)a * (Integer)b);

Basically, it is used to represent generic types. For example, JSON.deserialize returns an Object-- you then cast that Object into the appropriate type, such as a class, a primitive, or an SObject. Similarly, JSON.serialize accepts an object as a parameter-- the function takes all of the properties of the object and serialize them. There are several functions that take generic objects as their parameters, or return generic objects, in order to support a wide range of parameters.

All Answers

digamber.prasaddigamber.prasad

Hi,

 

In salesforce, we have sObject, not Object. Do you mean you want to know about sObject?

 

Happy to help you!

 

Regards,

Digamber Prasad

ThisIsRSNThisIsRSN

Hi Digamber,

 

Thanks for your reply.

 

I am aware of SObject. But there is a generic object called "Object" in Java. This object can be used in Apex also. But i can't see some of  its the methods in Apex say getClass(). When i tried to use it , it throws error.

So, i wanted to know the scope of this type ("Object") in apex.

 

Thanks

Rajendra

 

sfdcfoxsfdcfox

Object is analogous to Java's java.lang.Object. However, unlike java.lang.Object, it has no static or instance methods or properties. In other words, it can only be used as a dynamic data type that can refer to any other type. Any data type may be implicitly stored as an object (no casting required), but requires a cast to convert the object to any other data type. Most of the valueof static methods support object as a parameter, and the operators ==, !=, ===, and instanceof support objects as operands.

 

You can do the following things with Object:

 

Object a = 5, b = 7, c = 5;
System.assert(a != b);
System.assert(a == c);
System.assert(a != null);
System.assert(a instanceof Integer);
System.assert(String.valueOf(a) == '5');
System.assert(35 == (Integer)a * (Integer)b);

Basically, it is used to represent generic types. For example, JSON.deserialize returns an Object-- you then cast that Object into the appropriate type, such as a class, a primitive, or an SObject. Similarly, JSON.serialize accepts an object as a parameter-- the function takes all of the properties of the object and serialize them. There are several functions that take generic objects as their parameters, or return generic objects, in order to support a wide range of parameters.

This was selected as the best answer
ThisIsRSNThisIsRSN

Thanks Fox, This is the answer i was expecting. :)