Google says that SObjects are records from database and nothing more and Object is the class that is at the top of the hierarchy of inheritance and I think it's not enough to answer properly so any additional information would help a lot
1 Answer
If you've ever written a program that makes use of a database before, you're probably familiar with Data Transfer Objects, Database Abstraction Layers, and Object Relational Mappers. SObjects sidestep the need for us to worry about that.
An SObject is how Salesforce chose to represent "database" records in Apex. It's a way to bridge the gap between how Apex treats data (everything is an object) and how databases store data. In Apex, all we have to think about is that these are objects (I don't mean things of the Object
type here, though they are Object
instances as well, via inheritance).
It also provides us a nice level of abstraction so that we don't need to know the details of which databases and related technologies Salesforce uses to store data behind the scenes. We write queries and get SObject
s as a result, or we can create in-memory instances of SObject
s. In the end SObject data is manipulated in Apex and then we use DML (insert, update, delete, etc...) to persist those changes in the "database".
The Object
class itself isn't too useful to us. It sits near the top of the type system used by Apex (there's Any
and null
, which are their own things. I wouldn't recommend diving into formal type theory unless abstract math is exciting to you). On the Salesforce platform, its main use is in object serialization and deserialization.
Object
but it is basically the same as Java's Object.