function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
KierenJamesonKierenJameson 

Why is Object a primitive data type in Apex?

I'm curious if someone can clear up a confusion of mine about Apex primitive data types. I understand in Java that what makes something a primitive data type is a couple of things:
  1. That it can't be broken down into a smaller unit (e.g., array = non-primitive, long = primitive)
  2. That primitives are passed by value rather than passed by reference (e.g., boolean = primitive, object reference = non-primitive. )
This is where I get stuck translating this to Apex, because according to the Force.com Apex Code Dev Guide in Apex, Object is a primitive value (https://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm), and I don't think that it abides by either of the rules above.

Does Apex have a different definition of what makes something primitive than Java? If so, what is it?

I would be super grateful for someone to help clear this up for me :)
 
Best Answer chosen by KierenJameson
PratikPratik (Salesforce Developers) 
Hi Kieren,

Thanks for the document link. Ther it's mentioned:

Any data type that is supported in Apex—primitive data types (such as Integer), user-defined custom classes, the sObject generic type, or an sObject specific type (such as Account). All Apex data types inherit from Object.

So object itself is data type of sObject. Like i mentioned above post, you can create instance for an object.

Thanks,
Pratik

All Answers

PratikPratik (Salesforce Developers) 
Hi Kieren,

Please go through the below link:
https://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_data_types.htm

A primitive, such as an Integer, Double, Long, Date, Datetime, String, ID, or Boolean 
An sObject, either as a generic sObject or as a specific sObject, such as an Account, Contact, or MyCustomObject__c 

So you can consider SObject as class for which you can create an instance. In database terminology Object/sObject is a Table and the fields on the objects are the Columns of that table. 

Please let  me know if any further questions.

Thanks,
Pratik
KierenJamesonKierenJameson
Hey Pratik,

Thanks so much for responding. Sorry I used the wrong url (my bad!). I saw the information in the url you sent, but if I go one step down into the documentation I see that Object is referred to as a primitive data type: http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_primitives.htm

Thoughts?
Kieren
PratikPratik (Salesforce Developers) 
Hi Kieren,

Thanks for the document link. Ther it's mentioned:

Any data type that is supported in Apex—primitive data types (such as Integer), user-defined custom classes, the sObject generic type, or an sObject specific type (such as Account). All Apex data types inherit from Object.

So object itself is data type of sObject. Like i mentioned above post, you can create instance for an object.

Thanks,
Pratik
This was selected as the best answer
KierenJamesonKierenJameson
Thanks Pratik :)  I also got a great couple of explanations via a couple of new blog posts that were sent on to me from others:

https://developer.salesforce.com/blogs/developer-relations/2012/05/passing-parameters-by-reference-and-by-value-in-apex.html
and http://www.jitendrazaa.com/blog/java/pass-by-value-and-pass-by-reference/

'...everything in Apex is pass by value but that value is a pointer to the original value thus making everything work like pass by reference. Since all data types follow this rule then the Apex definition of Primitive Data Types seems to be "whatever we want to call a Primitive Data Type." '
 
PratikPratik (Salesforce Developers) 
Thanks Kieren for sharing information. It's really valuable.

Thanks,
Pratik