1

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

7
  • Can you go into more detail about what exactly you find lacking in that result? Are you familiar with OOP (Object Oriented Programming)? If you're not very familiar with OOP, doing some self-study on that will help you understand the Salesforce platform a bit better (rather, it's helpful to have some basic OOP knowledge before trying to figure out Salesforce).
    – Derek F
    Dec 28, 2020 at 18:47
  • well i'm familiar with oop but it doesn't help me, I tried to google on my own for information I need but seems like I can't write a proper request or something like that
    – Mark
    Dec 28, 2020 at 18:51
  • 1
    Sounds to me like you need to visit the trailheads for Salesforce, including that for SObject. These are Salesforce entities. Note that there's not much documentation for Apex Object but it is basically the same as Java's Object.
    – Phil W
    Dec 28, 2020 at 18:55
  • well i know that Object in apex is similar to Java's Object, but what is SObject except that this is apex representation of the record from database
    – Mark
    Dec 28, 2020 at 18:57
  • Am i correct saying that SObject is apex representation of the record from database?
    – Mark
    Dec 28, 2020 at 18:59

1 Answer 1

3

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 SObjects as a result, or we can create in-memory instances of SObjects. 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.

1
  • ANY is the underlying representation of Object.
    – sfdcfox
    Dec 28, 2020 at 21:57

Not the answer you're looking for? Browse other questions tagged .